src/common.c: Fix strstripnewline().
authorFlorian Forster <octo@collectd.org>
Wed, 10 Sep 2014 14:54:26 +0000 (16:54 +0200)
committerFlorian Forster <octo@collectd.org>
Wed, 10 Sep 2014 14:54:26 +0000 (16:54 +0200)
Because the length of the string was decremented too late, the function
would actually overwrite the trailing null byte instead of the newline.

src/common.c

index 9c4e64f..b771f62 100644 (file)
@@ -370,8 +370,8 @@ size_t strstripnewline (char *buffer)
                if ((buffer[buffer_len - 1] != '\n')
                                && (buffer[buffer_len - 1] != '\r'))
                        break;
-               buffer[buffer_len] = 0;
                buffer_len--;
+               buffer[buffer_len] = 0;
        }
 
        return (buffer_len);