From 2cbc84ccd1b0e1ce4d683cd5c8dddea3b40fbadc Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 28 Feb 2015 11:03:44 +0100 Subject: [PATCH] parser/inpgtok.c, use copy_substring() --- src/spicelib/parser/inpgtok.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/spicelib/parser/inpgtok.c b/src/spicelib/parser/inpgtok.c index 3fe9861fe..28fdd48f1 100644 --- a/src/spicelib/parser/inpgtok.c +++ b/src/spicelib/parser/inpgtok.c @@ -30,7 +30,6 @@ INPgetTok(char **line, char **token, int gobble) { char *point; int signstate; - int diffpoints; /* scan along throwing away garbage characters until end of line or a separation char is found */ @@ -104,12 +103,9 @@ INPgetTok(char **line, char **token, int gobble) if (point == *line && *point) /* Weird items, 1 char */ point++; - diffpoints = (int)(point - *line); - *token = TMALLOC(char, 1 + diffpoints); + *token = copy_substring(*line, point); if (!*token) return (E_NOMEM); - (void) strncpy(*token, *line, (size_t) diffpoints); - *(*token + diffpoints) = '\0'; *line = point; @@ -150,7 +146,6 @@ INPgetNetTok(char **line, char **token, int gobble) /* gobble: eat non-whitespace trash AFTER token? */ { char *point; - int diffpoints; /* scan along throwing away garbage characters until end of line or a separation char is found */ @@ -194,12 +189,9 @@ INPgetNetTok(char **line, char **token, int gobble) if (point == *line && *point) /* Weird items, 1 char */ point++; - diffpoints = (int)(point - *line); - *token = TMALLOC(char, 1 + diffpoints); + *token = copy_substring(*line, point); if (!*token) return (E_NOMEM); - (void) strncpy(*token, *line, (size_t) diffpoints); - *(*token + diffpoints) = '\0'; *line = point; @@ -325,11 +317,9 @@ INPgetUTok(char **line, char **token, int gobble) if (point == *line && *point) /* Weird items, 1 char */ point++; - *token = TMALLOC(char, 1 + point - *line); + *token = copy_substring(*line, point); if (!*token) return (E_NOMEM); - (void) strncpy(*token, *line, (size_t) (point - *line)); - *(*token + (point - *line)) = '\0'; /* gobble garbage to next token */ for (; *point != '\0'; point++) { @@ -465,11 +455,9 @@ INPgetU2Tok(char **line, char **token, int gobble) if (point == *line && *point) /* Weird items, 1 char */ point++; - *token = TMALLOC(char, 1 + point - *line); + *token = copy_substring(*line, point); if (!*token) return (E_NOMEM); - (void) strncpy(*token, *line, (size_t) (point - *line)); - *(*token + (point - *line)) = '\0'; /* gobble garbage to next token */ for (; *point != '\0'; point++) {