Skip to content

Commit 82d41b1

Browse files
committed
toke: fix getopt with invalid combined short options
When combining invalid short options, toke just segfaults: $ toke -ab Welcome to toke - FCode tokenizer v1.0.3 (C) Copyright 2001-2010 Stefan Reinauer. (C) Copyright 2006 coresystems GmbH (C) Copyright 2005 IBM Corporation. All Rights Reserved. This program is free software; you may redistribute it under the terms of the GNU General Public License v2. This program has absolutely no warranty. ./toke: invalid option -- 'a' ./toke: invalid option -- 'b' Segmentation fault (core dumped) This happens because argindx represent the number of the option, not the number of the argument on the command line. Fix that by looking at the optopt variable instead. Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
1 parent 7d392bb commit 82d41b1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

toke/toke.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ static void get_args( int argc, char **argv )
298298
/* Distinguish between a '?' from the user
299299
* and one getopt() returned
300300
*/
301-
if ( argv[argindx][1] != '?' )
301+
if ( optopt )
302302
{
303303
inval_opt = TRUE;
304304
break;

0 commit comments

Comments
 (0)