Skip to content

Commit

Permalink
Fix a variable logic and add a brace pair (#1890)
Browse files Browse the repository at this point in the history
* getoptx.c threw a compiler warning - and rightfully. This patch fixes
the logic of one variable with and without STRICT being defined.
Fix one missing brace pair on the way.

* 2nd attempt - non-intrusive

---------

Co-authored-by: Florian Zimmermann <florianzimmermann@duck.com>
  • Loading branch information
floriangit and Florian Zimmermann authored Apr 23, 2024
1 parent 9b90381 commit a7684d7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions elks/tools/mfs/getoptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ getoptX(int argc, char *const *argv, const char *optstring)
/* allowed args, e.g. "ab:c" */
{
static int sp = 1; /* position within argument */
register int osp; /* saved `sp' for param test */
#ifndef STRICT
register int oind; /* saved `optind' for param test */
#else
register int osp; /* saved `sp' for param test */
#endif
register int c; /* option letter */
register char *cp; /* -> option in `optstring' */
Expand All @@ -61,7 +62,10 @@ getoptX(int argc, char *const *argv, const char *optstring)
}
}
c = argv[optind][sp]; /* option letter */
osp = sp++; /* get ready for next letter */
#ifdef STRICT
osp = sp;
#endif
sp++; /* get ready for next letter */

#ifndef STRICT
oind = optind; /* save optind for param test */
Expand Down Expand Up @@ -96,11 +100,13 @@ getoptX(int argc, char *const *argv, const char *optstring)
else
#endif
if (optind >= argc)
{
return Err(argv[0], "option requires an argument", c);

}
else /* argument w/ whitespace */
{
optarg = argv[optind];

}
++optind; /* skip over parameter */
}

Expand Down

0 comments on commit a7684d7

Please sign in to comment.