From 39d8c4ce9178dd0f1cd4d58c680a226f50cc9ad3 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 20 Apr 2003 15:56:58 +0000 Subject: [PATCH] make getfid() more robust and fixed gcc warning git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2551 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- as/mcs51/lklex.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/as/mcs51/lklex.c b/as/mcs51/lklex.c index 7003ab2d..daaa4f32 100644 --- a/as/mcs51/lklex.c +++ b/as/mcs51/lklex.c @@ -160,13 +160,13 @@ char *id; * int c this is first character to * copy to the string buffer * - * The function getfid() scans the current input text line - * from the current position copying the next string - * into the external string buffer (str). The string ends when a - * non SPACE type character is found. The maximum number of - * characters copied is PATH_MAX. If the input string is larger than - * PATH_MAX characters then the string is truncated, if the input string - * is shorter than PATH_MAX characters then the string is NULL filled. + * The function getfid() scans the current input text line from + * the current position copying the next string into the external + * string buffer (str). The string ends when end of line is found. + * Trailing spacers are removed. The maximum number of characters + * copied is PATH_MAX. If the input string is larger than PATH_MAX + * characters then the string is truncated. The string is NULL + * terminated. * * local variables: * char * p pointer to external string buffer @@ -194,16 +194,18 @@ char *str; register char *p; p = str; - do { + do + { if (p < &str[PATH_MAX-1]) *p++ = c; c = get(); } while (c); - /* trim trailing spaces */ - while (ctype[*(--p)] == SPACE) - ; - /* terminate the string */ - *(++p) = '\0'; + /* trim trailing spaces */ + --p; + while (p >= str && ctype[(int)*p] == SPACE) + --p; + /* terminate the string */ + *(++p) = '\0'; } /*)Function char getnb() -- 2.30.2