Skip to content

Commit

Permalink
fix gcc warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Gatto <[email protected]>
  • Loading branch information
outscale-mgo committed Feb 5, 2024
1 parent 63d8ff4 commit 82bea3f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions cognac_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ EOF
int aret = 0;
int incr = aa ? 2 : 1;
(void)str;
if (aa && aa[0] == '-' && aa[1] == '-' && aa[2] != '-') {
if (!strcmp(aa, "--file")) {
TRY(i + 3 >= ac, "file name require");
Expand Down
2 changes: 1 addition & 1 deletion construct_data.c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ EOF
TRY_APPEND_COL(count_args, data);
STRY(osc_str_append_string(data, "\"$x\\":[" ));
for (as = args->$snake_x; *as > 0; ++as) {
for (as = args->$snake_x; *as; ++as) {
if (as != args->$snake_x)
STRY(osc_str_append_string(data, "," ));
ARG_TO_JSON_STR("", *as);
Expand Down
10 changes: 7 additions & 3 deletions main-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ struct ptr_array {
int oidx = ptr_array_get_idx(pa, s->a); \
s->a = osc_realloc(s->a, sz * size); \
CHK_BAD_RET(!s->a, "allocation fail\n"); \
if (oidx < 0) \
ptr_array_append(pa, s->a); \
else { \
if (oidx < 0) { \
CHK_BAD_RET(ptr_array_append(pa, s->a) < 0, \
"ptr_array_append fail"); \
} else { \
pa->ptrs[oidx] = s->a; \
s->a = pa->ptrs[oidx]; \
} \
Expand Down Expand Up @@ -60,7 +61,10 @@ static inline int ptr_array_append(struct ptr_array *pa, void *ptr)
pa->size += 64;
pa->ptrs = realloc(old, pa->size);
if (!pa->ptrs) {
/* if realloc return NULL. old is left untouched */
#pragma GCC diagnostic ignored "-Wuse-after-free"
free(old);
#pragma GCC diagnostic pop
return -1;
}
}
Expand Down
14 changes: 9 additions & 5 deletions main_tpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,32 @@ char *read_file(char *files_cnt[static MAX_FILES_PER_CMD], char *file_name,
}
if (fseek(f, 0, SEEK_END) < 0) {
fprintf(stderr, "%s fseek fail for %s", call_name, file_name);
return NULL;
goto error;
}
long fsize = ftell(f);
if (fseek(f, 0, SEEK_SET) < 0) {
fprintf(stderr, "%s fseek fail for %s", call_name, file_name);
return NULL;
goto error;
}

files_cnt[dest] = malloc(fsize + 1);
if (!files_cnt[dest]) {
fprintf(stderr, "%s malloc fail for %s", call_name, file_name);
return NULL;
goto error;
}
if (fread(files_cnt[dest], fsize, 1, f) < 0) {
fread(files_cnt[dest], fsize, 1, f);
if (ferror(f)) {
fprintf(stderr, "%s fread fail for %s", call_name, file_name);
return NULL;
goto error;
}
fclose(f);
files_cnt[dest][fsize] = 0;
if (is_json)
return string_to_jsonstr(&files_cnt[dest]);
return files_cnt[dest];
error:
fclose(f);
return NULL;
}


Expand Down
2 changes: 1 addition & 1 deletion oapi-cli.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#-Wincompatible-pointer-types
oapi-cli: $(OAPI_RULE_DEPEDENCIES) $(JSON_C_RULE)
$(CC) -g main.c osc_sdk.c $(CURL_LD) $(JSON_C_LDFLAGS) $(CURL_CFLAGS) $${CURL_BASH_CFLAGS} $(JSON_C_CFLAGS) -o oapi-cli -DWITH_DESCRIPTION=1 $(CFLAGS)
$(CC) -g -Wall -Wextra -Wno-unused-function -Wno-unused-parameter main.c osc_sdk.c $(CURL_LD) $(JSON_C_LDFLAGS) $(CURL_CFLAGS) $${CURL_BASH_CFLAGS} $(JSON_C_CFLAGS) -o oapi-cli -DWITH_DESCRIPTION=1 $(CFLAGS)

appimagetool-x86_64.AppImage:
wget https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
Expand Down

0 comments on commit 82bea3f

Please sign in to comment.