Ignore:
Timestamp:
Aug 6, 2008, 10:58:31 PM (12 years ago)
Author:
Pascal Terjan
Message:
  • Don't crash when an option with mandatory argument is passed last
File:
1 edited

Legend:

Unmodified
Added
Removed
  • neercs/trunk/src/mygetopt.c

    r2547 r2675  
    6464                myoptarg = flag + 2;
    6565            else
    66                 myoptarg = argv[myoptind++];
     66                if(myoptind >= argc)
     67                {
     68                    fprintf(stderr, "%s: `%s' needs an argument\n", argv[0], flag);
     69                    return -2;
     70                }
     71                else
     72                    myoptarg = argv[myoptind++];
    6773            return ret;
    6874        }
Note: See TracChangeset for help on using the changeset viewer.