diff options
Diffstat (limited to 'cudl.c')
-rw-r--r-- | cudl.c | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -1,6 +1,7 @@ #include <stdio.h> #include <ctype.h> #include <stdlib.h> +#include <string.h> #include "cudl.h" #define STRIP_WHITESPACE(text) while (isspace(*text)) text++ @@ -59,7 +60,7 @@ void cudl_deinit_value(struct cudl_value value) { free(value.data.array.values); break; case CUDL_TAG_NULL: - case default: + default: break; } } @@ -67,19 +68,19 @@ void cudl_deinit_value(struct cudl_value value) { /* Parse a value from input and store it in value. * Return the number of bytes consumed. * Input must end with a null byte */ -size_t parse_value(char *input, struct cudl_value *value); +static size_t parse_value(char *input, struct cudl_value *value); static size_t parse_bool_or_null(char *input, struct cudl_value *value) { - if (strncmp(input, "null", 4)) { + if (strncmp(input, "null", 4) == 0) { value->tag = CUDL_TAG_NULL; return 4; } - if (strncmp(input, "true", 4)) { + if (strncmp(input, "true", 4) == 0) { value->tag = CUDL_TAG_BOOL; value->data.boolean = 1; return 4; } - if (strncmp(input, "false", 5)) { + if (strncmp(input, "false", 5) == 0) { value->tag = CUDL_TAG_BOOL; value->data.boolean = 0; return 5; @@ -158,8 +159,8 @@ static size_t parse_value(char *input, struct cudl_value *value) { } void cudl_parse_from_file(FILE *file, struct cudl_value *value) { - char *input; - if ((input = fread_all(file)) == NULL) { + char *input, *original_input; + if ((original_input = input = fread_all(file)) == NULL) { if (ferror(file)) cudl_err = CUDL_ERR_READING; else @@ -169,7 +170,7 @@ void cudl_parse_from_file(FILE *file, struct cudl_value *value) { input += cudl_parse(input, value); if (*input != '\0') cudl_deinit_value(*value); - free(input); + free(original_input); } size_t cudl_parse(char *input, struct cudl_value *value) { |