Compiler flag -Wconversion

Makes type conversions explicit, if they alter a value
This commit is contained in:
Max Bruckner
2017-02-03 18:34:37 +01:00
parent 41e2837df1
commit 3d3bfc6a4d
5 changed files with 81 additions and 43 deletions

8
test.c
View File

@@ -97,8 +97,8 @@ static int print_preallocated(cJSON *root)
char *out = NULL;
char *buf = NULL;
char *buf_fail = NULL;
int len = 0;
int len_fail = 0;
size_t len = 0;
size_t len_fail = 0;
/* formatted print */
out = cJSON_Print(root);
@@ -123,7 +123,7 @@ static int print_preallocated(cJSON *root)
}
/* Print to buffer */
if (!cJSON_PrintPreallocated(root, buf, len, 1)) {
if (!cJSON_PrintPreallocated(root, buf, (int)len, 1)) {
printf("cJSON_PrintPreallocated failed!\n");
if (strcmp(out, buf) != 0) {
printf("cJSON_PrintPreallocated not the same as cJSON_Print!\n");
@@ -140,7 +140,7 @@ static int print_preallocated(cJSON *root)
printf("%s\n", buf);
/* force it to fail */
if (cJSON_PrintPreallocated(root, buf_fail, len_fail, 1)) {
if (cJSON_PrintPreallocated(root, buf_fail, (int)len_fail, 1)) {
printf("cJSON_PrintPreallocated failed to show error with insufficient memory!\n");
printf("cJSON_Print result:\n%s\n", out);
printf("cJSON_PrintPreallocated result:\n%s\n", buf_fail);