When possible convert allocation + copy of a memory buffer or a string to x{mem,str}dup(). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- pre-process.c | 10 +++------- tokenize.c | 9 ++------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/pre-process.c b/pre-process.c index 88be02f1e..403d899c3 100644 --- a/pre-process.c +++ b/pre-process.c @@ -543,13 +543,10 @@ static int merge(struct token *left, struct token *right) left->pos.noexpand = 0; return 1; - case TOKEN_NUMBER: { - char *number = __alloc_bytes(strlen(buffer) + 1); - memcpy(number, buffer, strlen(buffer) + 1); + case TOKEN_NUMBER: token_type(left) = TOKEN_NUMBER; /* could be . + num */ - left->number = number; + left->number = xstrdup(buffer); return 1; - } case TOKEN_SPECIAL: if (buffer[2] && buffer[3]) @@ -900,8 +897,7 @@ static int try_include(const char *path, const char *filename, int flen, struct return 1; fd = open(fullname, O_RDONLY); if (fd >= 0) { - char * streamname = __alloc_bytes(plen + flen); - memcpy(streamname, fullname, plen + flen); + char *streamname = xmemdup(fullname, plen + flen); *where = tokenize(streamname, fd, *where, next_path); close(fd); return 1; diff --git a/tokenize.c b/tokenize.c index 1118786f6..fa7890d38 100644 --- a/tokenize.c +++ b/tokenize.c @@ -528,8 +528,7 @@ static int get_one_number(int c, int next, stream_t *stream) { struct token *token; static char buffer[4095]; - char *p = buffer, *buf, *buffer_end = buffer + sizeof (buffer); - int len; + char *p = buffer, *buffer_end = buffer + sizeof (buffer); *p++ = c; for (;;) { @@ -557,13 +556,9 @@ static int get_one_number(int c, int next, stream_t *stream) } *p++ = 0; - len = p - buffer; - buf = __alloc_bytes(len); - memcpy(buf, buffer, len); - token = stream->token; token_type(token) = TOKEN_NUMBER; - token->number = buf; + token->number = xmemdup(buffer, p - buffer); add_token(stream); return next; -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html