[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bash 2.05 'unsigned char' cleanup

From: Paul Eggert
Subject: Re: Bash 2.05 'unsigned char' cleanup
Date: Tue, 8 May 2001 09:52:46 -0700 (PDT)

> From: "Brian J. Fox" <address@hidden>
> Date: Mon, 07 May 2001 21:20:54 -0700
>    The simplest fix is to add one byte to 'sample' and to initialize it
>    to zero, which is what my proposed patch does.  Once you do this, the
>    code gets a bit simpler anyway.
> I would think that the simplest fix would be to check the length first:

Yes, that would be a smaller change; but the fix I proposed results in
smaller and faster code, since it avoids the length check entirely.

> #  define WHITECHAR(ind) \
>     (ind < sample_len && whitespace (sample[ind]) && sample[ind] != '\n')

OK, but X cannot be '\n' if whitespace(X) is nonzero, so the check for
'\n' is redundant and confusing.

Come to think of it, the patched code can be simplified slightly
further, as follows:

2001-05-08  Paul Eggert  <address@hidden>

        * execute_cmd.c (execute_shell_script): Don't bother taking
        sample_len arg, as the sample is null-terminated anyway.

RCS file: execute_cmd.c,v
retrieving revision
retrieving revision
diff -pu -r2.5.0.8 -r2.5.0.9
--- execute_cmd.c       2001/05/07 19:44:31
+++ execute_cmd.c       2001/05/08 16:31:09
@@ -3228,13 +3228,11 @@ execute_disk_command (words, redirects, 
 #if !defined (HAVE_HASH_BANG_EXEC)
 /* If the operating system on which we're running does not handle
    the #! executable format, then help out.  SAMPLE is the text read
-   from the file, SAMPLE_LEN characters.  COMMAND is the name of
+   from the file; it must be null-terminated.  COMMAND is the name of
    the script; it and ARGS, the arguments given by the user, will
    become arguments to the specified interpreter.  ENV is the environment
    to pass to the interpreter.
-   SAMPLE[SAMPLE_LEN] must be zero.
    The word immediately following the #! is the interpreter to execute.
    A single argument to the interpreter is allowed. */
@@ -3253,9 +3251,8 @@ execute_disk_command (words, redirects, 
 #endif /* MSDOS */
 static int
-execute_shell_script (sample, sample_len, command, args, env)
+execute_shell_script (sample, command, args, env)
      char *sample;
-     int sample_len;
      char *command;
      char **args, **env;
@@ -3437,7 +3434,7 @@ shell_execve (command, args, env)
       if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
          sample[sample_len] = '\0';
-         return (execute_shell_script (sample, sample_len, command, args, 
+         return (execute_shell_script (sample, command, args, env));

reply via email to

[Prev in Thread] Current Thread [Next in Thread]