Skip to content

Commit

Permalink
exeflat failed to advance str so didn't actually skip whitespace at b…
Browse files Browse the repository at this point in the history
…eginning of string, additional comments
  • Loading branch information
PerditionC committed Aug 18, 2024
1 parent 8f056cc commit 2ce6dc0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions utils/exeflat.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,18 @@ int my_isspace( int c )
}
}

/* read command line argument from open FILE referenced by fp */
char *getarg( FILE *fp )
{
static char buff[256];
char *str;
size_t len;

/* loop reading through file until end or new line or max characters */
while( (str = fgets( buff, sizeof(buff) - 1, fp )) != NULL ) {
buff[sizeof(buff) - 1] = '\0';
buff[sizeof(buff) - 1] = '\0'; /* ensure buffer is terminated */
len = strlen(buff);
/* strip whitespace from end of string, i.e. "blah " --> "blah" */
while( len > 0 ) {
len--;
if( my_isspace( buff[len] ) ) {
Expand All @@ -442,11 +445,17 @@ char *getarg( FILE *fp )
len++;
break;
}
while( len-- > 0 ) {
/* skip past whitespace at beginning of string */
/* str initially points to start of buff */
while( len > 0 ) {
/* stop when str points to end of string or 1st non-space character */
if( !my_isspace(*str) ) {
break;
}
str++;
len--;
}
/* if we got a blank line (*str=='\0') then keep looping, otherwise return what found */
if( *str != '\0' ) {
break;
}
Expand Down

0 comments on commit 2ce6dc0

Please sign in to comment.