From: Paul Eggert Date: Sun, 19 Jun 2011 18:37:51 +0000 (-0700) Subject: * emacs.c: Don't assume string length fits in 'int'. X-Git-Tag: emacs-pretest-24.0.90~104^2~473^2~32 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0b963a931c2ba66829dbdb8489fe83e100d2326c;p=emacs.git * emacs.c: Don't assume string length fits in 'int'. (DEFINE_DUMMY_FUNCTION, sort_args): Use ptrdiff_t, not int. (main): Don't invoke strlen when not needed. --- diff --git a/src/ChangeLog b/src/ChangeLog index 3a7cad71c35..cc10da99d83 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2011-06-19 Paul Eggert + * emacs.c: Don't assume string length fits in 'int'. + (DEFINE_DUMMY_FUNCTION, sort_args): Use ptrdiff_t, not int. + (main): Don't invoke strlen when not needed. + * dbusbind.c (XD_ERROR): Don't arbitrarily truncate string. (XD_DEBUG_MESSAGE): Don't waste a byte. diff --git a/src/emacs.c b/src/emacs.c index d14acd63587..c4b4caad9b5 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -585,7 +585,7 @@ argmatch (char **argv, int argc, const char *sstr, const char *lstr, int minlen, char **valptr, int *skipptr) { char *p = NULL; - int arglen; + ptrdiff_t arglen; char *arg; /* Don't access argv[argc]; give up in advance. */ @@ -1087,7 +1087,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem dname_arg2[0] = '\0'; sscanf (dname_arg, "\n%d,%d\n%s", &(daemon_pipe[0]), &(daemon_pipe[1]), dname_arg2); - dname_arg = strlen (dname_arg2) ? dname_arg2 : NULL; + dname_arg = *dname_arg2 ? dname_arg2 : NULL; } #endif /* NS_IMPL_COCOA */ @@ -1846,8 +1846,7 @@ sort_args (int argc, char **argv) priority[from] = 0; if (argv[from][0] == '-') { - int match, thislen; - char *equals; + int match; /* If we have found "--", don't consider any more arguments as options. */ @@ -1879,11 +1878,11 @@ sort_args (int argc, char **argv) >= 0 (the table index of the match) if just one match so far. */ if (argv[from][1] == '-') { + char const *equals = strchr (argv[from], '='); + ptrdiff_t thislen = + equals ? equals - argv[from] : strlen (argv[from]); + match = -1; - thislen = strlen (argv[from]); - equals = strchr (argv[from], '='); - if (equals != 0) - thislen = equals - argv[from]; for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)