Skip to content

Commit 2ce6dc0

Browse files
committed
exeflat failed to advance str so didn't actually skip whitespace at beginning of string, additional comments
1 parent 8f056cc commit 2ce6dc0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

utils/exeflat.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,15 +424,18 @@ int my_isspace( int c )
424424
}
425425
}
426426

427+
/* read command line argument from open FILE referenced by fp */
427428
char *getarg( FILE *fp )
428429
{
429430
static char buff[256];
430431
char *str;
431432
size_t len;
432433

434+
/* loop reading through file until end or new line or max characters */
433435
while( (str = fgets( buff, sizeof(buff) - 1, fp )) != NULL ) {
434-
buff[sizeof(buff) - 1] = '\0';
436+
buff[sizeof(buff) - 1] = '\0'; /* ensure buffer is terminated */
435437
len = strlen(buff);
438+
/* strip whitespace from end of string, i.e. "blah " --> "blah" */
436439
while( len > 0 ) {
437440
len--;
438441
if( my_isspace( buff[len] ) ) {
@@ -442,11 +445,17 @@ char *getarg( FILE *fp )
442445
len++;
443446
break;
444447
}
445-
while( len-- > 0 ) {
448+
/* skip past whitespace at beginning of string */
449+
/* str initially points to start of buff */
450+
while( len > 0 ) {
451+
/* stop when str points to end of string or 1st non-space character */
446452
if( !my_isspace(*str) ) {
447453
break;
448454
}
455+
str++;
456+
len--;
449457
}
458+
/* if we got a blank line (*str=='\0') then keep looping, otherwise return what found */
450459
if( *str != '\0' ) {
451460
break;
452461
}

0 commit comments

Comments
 (0)