Message ID | 20181208093441.10886-1-mhei@heimpold.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [mmc-utils] One further optimization of trimming routine | expand |
diff --git a/lsmmc.c b/lsmmc.c index 9737b37..86be802 100644 --- a/lsmmc.c +++ b/lsmmc.c @@ -358,10 +358,9 @@ char *read_file(char *name) start++; len--; } - memmove(line, start, len); - line[len] = '\0'; + start[len] = '\0'; - return strdup(line); + return strdup(start); } /* Hexadecimal string parsing functions */
The last change to the trimming routine made it more efficient, however, we can even get rid of the memmove() as we leave the function with strdup() anyway. Signed-off-by: Michael Heimpold <mhei@heimpold.de> I got a compile error with GCC7. When trimming white spaces from strings lsmmc uses strncpy with overlapping memory areas. This is not allowed. In addition, the implementation was not efficient with calling strlen and strncpy once per iteration. Refactor the code to be valid and more effective. --- lsmmc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)