From 5e58f09fcfc346e1e9953cf30c403ce1052ba3b4 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 15 Apr 2016 13:07:58 +0100 Subject: [PATCH] Don't trash original string when working with flags. #funwithflags --- src/system/lookup.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/system/lookup.c b/src/system/lookup.c index dcb24f2..161e310 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -265,17 +265,20 @@ char *getFlagValues(char *prefix, long flags) return flagStr; } -long flagsToLong(char *flags, int *add) +long flagsToLong(char *in, int *add) { - char *flag; + char *flag, *flags; long total; - + total = 0; if (add) { - *add = (flags[0] == '+'); + *add = (in[0] == '+'); } + + flags = malloc(strlen(in) + 1); + STRNCPY(flags, in, strlen(in) + 1); flag = strtok(flags, "+"); while (flag) @@ -283,6 +286,8 @@ long flagsToLong(char *flags, int *add) total += lookup(flag); flag = strtok(NULL, "+"); } + + free(flags); return total; }