-
Notifications
You must be signed in to change notification settings - Fork 104
Raise the warning level to -Wall -Wextra and resolve the warnings #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/v2.4.9.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,5 @@ GTAGS | |
| TAGS | ||
| tags | ||
| *~ | ||
| compile_commands.json | ||
| .cache/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -461,7 +461,11 @@ dnl Update flags | |
| dnl Sets CFLAGS to force optimization and debugging options, which isn't quite kosher | ||
| dnl | ||
| AM_CPPFLAGS="-D_GNU_SOURCE -I\$(top_srcdir)/src -DLTFS_CONFIG_FILE='\"${sysconfdir}/ltfs.conf\"' -DLTFS_BASE_DIR='\"${prefix}\"'" | ||
| AM_CFLAGS="-Wall -Wsign-compare -fsigned-char ${FUSE_MODULE_CFLAGS} ${UUID_MODULE_CFLAGS} ${LIBXML2_MODULE_CFLAGS} ${ICU_MODULE_CFLAGS} ${SNMP_ENABLE} ${SNMP_MODULE_CFLAGS}" | ||
| dnl -Wno-unused-parameter: callback signatures (FUSE operations, plugin ops) | ||
| dnl must keep parameters they do not use. | ||
| dnl -Wno-missing-field-initializers: designated initializers of operation and | ||
| dnl option tables intentionally leave the remaining members zeroed. | ||
| AM_CFLAGS="-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wsign-compare -fsigned-char ${FUSE_MODULE_CFLAGS} ${UUID_MODULE_CFLAGS} ${LIBXML2_MODULE_CFLAGS} ${ICU_MODULE_CFLAGS} ${SNMP_ENABLE} ${SNMP_MODULE_CFLAGS}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change overwrite whatever AM_CFLAGS contained before that could be carried from the environment. As the code below this and many others you should first add ${AM_CFLAGS} before adding others to avoid the overwrite. |
||
|
|
||
| if test "x$use_fast" = "xyes" | ||
| then | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2067,14 +2067,16 @@ int ltfs_fsops_target_absolute_path(const char* link, const char* target, char* | |
| len -= strlen(temp_buf); /* length of "/aaa" */ | ||
| } else if (strcmp(token, "." )) { /* have directory name */ | ||
| work_buf[len] = '/'; /* put '/ 'as "/aaa/" */ | ||
| arch_strncpy(work_buf+len+1, token, work_buf_len, strlen(token)); /* "/aaa/ccc\0" */ | ||
| memcpy(work_buf+len+1, token, strlen(token)); /* "/aaa/ccc\0" */ | ||
| work_buf[len+1+strlen(token)] = '\0'; | ||
|
Comment on lines
+2070
to
+2071
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds a new problem because now the bound put by work_buf_len is not there, making it possible for a buffer overwrite risk, consider other solution for the warning. |
||
| len = strlen(work_buf); | ||
| } | ||
| token = next_token; | ||
| } | ||
| work_buf[len] = '/'; /* put '/ 'as "/aaa/ccc/" */ | ||
| if(token){ | ||
| arch_strncpy(work_buf+len+1, token, work_buf_len, strlen(token)); /* "/aaa/ccc/target.txt\0" */ | ||
| memcpy(work_buf+len+1, token, strlen(token)); /* "/aaa/ccc/target.txt\0" */ | ||
| work_buf[len+1+strlen(token)] = '\0'; | ||
|
Comment on lines
+2078
to
+2079
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto about the problem with dropping work_buf_len. |
||
| } | ||
| if (size < strlen(work_buf) + 1) { | ||
| free(work_buf); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,6 +222,16 @@ struct ltfs_timespec start; | |
| struct timer_info timerinfo; | ||
| bool trace_enable = true; | ||
|
|
||
| /* The trace dump is best-effort diagnostics; a write failure must not fail | ||
| * the operation that triggered the dump. glibc marks write() with | ||
| * warn_unused_result and a (void) cast does not silence it, so consume the | ||
| * result here and deliberately ignore it. */ | ||
| static void _dump_write(int fd, const void *buf, size_t count) | ||
| { | ||
| ssize_t ignored = arch_write(fd, buf, count); | ||
| (void)ignored; | ||
| } | ||
|
|
||
|
Comment on lines
+225
to
+234
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This kind of solution that is just an static file single-wrapper and it's not done system wide seems a little bit overengineered. It hides the intent from the call sites and can't be reused anywhere else. A more idiomatic approach should be used like (void)!arch_write(...) at the call sites instead. |
||
| static int ltfs_request_trace_init(void) | ||
| { | ||
| int ret = 0; | ||
|
|
@@ -576,7 +586,7 @@ int ltfs_dump(char *fname, const char *work_dir) | |
| int ret = 0, num_args = 0, status; | ||
| char *path, *pid; | ||
| pid_t fork_pid; | ||
| const unsigned int max_arguments = 32; | ||
| enum { max_arguments = 32 }; | ||
| const char *args[max_arguments]; | ||
|
|
||
| if(!work_dir) | ||
|
|
@@ -694,37 +704,37 @@ int ltfs_trace_dump(char *fname, const char *work_dir) | |
| trc_header->header_size + req_header->header_size + fn_trc_header->header_size; | ||
|
|
||
| /* Write headers */ | ||
| (void)arch_write(fd, trc_header, sizeof(struct trace_header)); | ||
| (void)arch_write(fd, req_header, sizeof(struct request_header)); | ||
| _dump_write(fd, trc_header, sizeof(struct trace_header)); | ||
| _dump_write(fd, req_header, sizeof(struct request_header)); | ||
|
|
||
| /* Write request trace data */ | ||
| ltfs_mutex_lock(&req_trace->req_trace_lock); | ||
| (void)arch_write(fd, req_trace->entries, REQ_TRACE_SIZE); | ||
| _dump_write(fd, req_trace->entries, REQ_TRACE_SIZE); | ||
| ltfs_mutex_unlock(&req_trace->req_trace_lock); | ||
|
|
||
| /* Write function trace header */ | ||
| (void)arch_write(fd, &fn_trc_header->header_size, sizeof(uint32_t)); | ||
| (void)arch_write(fd, &fn_trc_header->num_of_fn_trace, sizeof(uint32_t)); | ||
| _dump_write(fd, &fn_trc_header->header_size, sizeof(uint32_t)); | ||
| _dump_write(fd, &fn_trc_header->num_of_fn_trace, sizeof(uint32_t)); | ||
| for (unsigned int i=0; i<n; i++) | ||
| (void)arch_write(fd, &fn_trc_header->req_t_desc[i], sizeof(struct function_trace_descriptor)); | ||
| (void)arch_write(fd, &fn_trc_header->crc, sizeof(uint32_t)); | ||
| _dump_write(fd, &fn_trc_header->req_t_desc[i], sizeof(struct function_trace_descriptor)); | ||
| _dump_write(fd, &fn_trc_header->crc, sizeof(uint32_t)); | ||
| free(fn_trc_header->req_t_desc); | ||
| fn_trc_header->req_t_desc = NULL; | ||
|
|
||
| /* Write function trace data */ | ||
| for (fsitem=fs_tr_list; fsitem != NULL; fsitem=fsitem->hh.next) { | ||
| acquireread_mrsw(&fsitem->fn_entry->trace_lock); | ||
| (void)arch_write(fd, fsitem->fn_entry->entries, FS_FN_TRACE_SIZE); | ||
| _dump_write(fd, fsitem->fn_entry->entries, FS_FN_TRACE_SIZE); | ||
| releaseread_mrsw(&fsitem->fn_entry->trace_lock); | ||
| } | ||
| for (admitem=admin_tr_list; admitem != NULL; admitem=admitem->hh.next) { | ||
| acquireread_mrsw(&admitem->fn_entry->trace_lock); | ||
| (void)arch_write(fd, admitem->fn_entry->entries, ADMIN_FN_TRACE_SIZE); | ||
| _dump_write(fd, admitem->fn_entry->entries, ADMIN_FN_TRACE_SIZE); | ||
| releaseread_mrsw(&admitem->fn_entry->trace_lock); | ||
| } | ||
| TAILQ_FOREACH (tailq_item, acomp, list) { | ||
| acquireread_mrsw(&tailq_item->fn_entry->trace_lock); | ||
| (void)arch_write(fd, tailq_item->fn_entry->entries, ADMIN_FN_TRACE_SIZE); | ||
| _dump_write(fd, tailq_item->fn_entry->entries, ADMIN_FN_TRACE_SIZE); | ||
| releaseread_mrsw(&tailq_item->fn_entry->trace_lock); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1782,8 +1782,9 @@ int tape_set_cart_coherency(struct device_data *dev, const tape_partition_t part | |
| /* APPLICATION CLIENT SPECIFIC INFORMATION LENGTH */ | ||
| coh_data[30] = 0; /* Size of APPLICATION CLIENT SPECIFIC INFORMATION (Byte 1) */ | ||
| coh_data[31] = 43; /* Size of APPLICATION CLIENT SPECIFIC INFORMATION (Byte 0) */ | ||
| /* Size of the buffer to insert 'LTFS' needs to be size of 5 for the 4 letters and the null terminator*/ | ||
| arch_strncpy((char *)coh_data + 32,"LTFS", 5, 4); | ||
| /* Bytes 32-36 hold the "LTFS" signature; the reader checks all five | ||
| * bytes, so copy the terminator explicitly. */ | ||
| memcpy(coh_data + 32, "LTFS", 5); | ||
| memcpy(coh_data + 37, coh->uuid, 37); | ||
| /* | ||
| Version field | ||
|
|
@@ -2978,7 +2979,7 @@ void parse_vol(char *str, int start_len, int end_len) | |
| */ | ||
| int u_get_truncate_size(const char *name, int name_len, int max_size) | ||
| { | ||
| int32_t size = 0, re_size; | ||
| int32_t size = 0, re_size = 0; | ||
| UChar32 c; | ||
| UErrorCode err = U_ZERO_ERROR; | ||
|
|
||
|
|
@@ -3001,6 +3002,17 @@ int u_get_truncate_size(const char *name, int name_len, int max_size) | |
| * @param Tape attribute | ||
| * @return 0: success, negative : cannot set correct value to tape_attr | ||
| */ | ||
| /* MAM attribute fields have fixed widths; truncation is intentional and | ||
| * parse_vol() pads and terminates afterwards. */ | ||
| static void mam_field_copy(char *dest, size_t field_size, const char *src) | ||
| { | ||
| size_t n = strlen(src); | ||
|
|
||
| if (n > field_size) | ||
| n = field_size; | ||
| memcpy(dest, src, n); | ||
| } | ||
|
|
||
|
Comment on lines
+3005
to
+3015
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue, single file solutions are not the best solutions, this also doesn't null terminate making the use of the function dependent on parse_vol() being called afterwards and not reusable. memcpy should be used instead in place instead of a custom wrapper. This also duplicates semantics already used in arch_strncpy. |
||
| void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) | ||
| { | ||
| int len_volname = 0; | ||
|
|
@@ -3016,16 +3028,16 @@ void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) | |
| } | ||
|
|
||
| /* APPLICATION VENDOR set */ | ||
| arch_strncpy_auto(t_attr->vender, LTFS_VENDOR_NAME, TC_MAM_APP_VENDER_SIZE); | ||
| mam_field_copy(t_attr->vender, TC_MAM_APP_VENDER_SIZE, LTFS_VENDOR_NAME); | ||
| parse_vol(t_attr->vender, strlen(LTFS_VENDOR_NAME), TC_MAM_APP_VENDER_SIZE); | ||
|
|
||
| /* APPLICATION NAME set */ | ||
| arch_strncpy_auto(t_attr->app_name, PACKAGE_NAME, TC_MAM_APP_NAME_SIZE); | ||
| mam_field_copy(t_attr->app_name, TC_MAM_APP_NAME_SIZE, PACKAGE_NAME); | ||
| parse_vol(t_attr->app_name, strlen(PACKAGE_NAME), TC_MAM_APP_NAME_SIZE); | ||
|
|
||
|
|
||
| /* APPLICATION VERSION set */ | ||
| arch_strncpy_auto(t_attr->app_ver, PACKAGE_VERSION, TC_MAM_APP_VERSION_SIZE); | ||
| mam_field_copy(t_attr->app_ver, TC_MAM_APP_VERSION_SIZE, PACKAGE_VERSION); | ||
| parse_vol(t_attr->app_ver, strlen(PACKAGE_VERSION), TC_MAM_APP_VERSION_SIZE); | ||
|
|
||
| /* USER MEDIUM LABEL set */ | ||
|
|
@@ -3039,7 +3051,7 @@ void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) | |
| if (len_volname == -LTFS_ICU_ERROR) | ||
| len_volname = TC_MAM_USER_MEDIUM_LABEL_SIZE - 1; | ||
| } | ||
| arch_strncpy(t_attr->medium_label, vol->index->volume_name.name, sizeof(t_attr->medium_label), len_volname); | ||
| memcpy(t_attr->medium_label, vol->index->volume_name.name, len_volname); | ||
| } | ||
|
|
||
| /* TEXT LOCALIZATION IDENTIFIER set */ | ||
|
|
@@ -3049,15 +3061,15 @@ void set_tape_attribute(struct ltfs_volume *vol, struct tape_attr *t_attr) | |
| if ( vol->label->barcode[0] ) { | ||
| if ( strlen(vol->label->barcode) > TC_MAM_BARCODE_SIZE) | ||
| ltfsmsg(LTFS_WARN, 17203W, "BARCODE", vol->label->barcode, TC_MAM_BARCODE_SIZE); | ||
| arch_strncpy_auto(t_attr->barcode, vol->label->barcode, TC_MAM_BARCODE_SIZE); | ||
| mam_field_copy(t_attr->barcode, TC_MAM_BARCODE_SIZE, vol->label->barcode); | ||
| parse_vol(t_attr->barcode, strlen(vol->label->barcode), TC_MAM_BARCODE_SIZE); | ||
| } else { | ||
| ltfsmsg(LTFS_WARN, 17230W); | ||
| parse_vol(t_attr->barcode, 0, TC_MAM_BARCODE_SIZE); | ||
| } | ||
|
|
||
| /* APPLICATION FORMAT VERSION set */ | ||
| arch_strncpy_auto(t_attr->app_format_ver, LTFS_INDEX_VERSION_STR, TC_MAM_APP_FORMAT_VERSION_SIZE); | ||
| mam_field_copy(t_attr->app_format_ver, TC_MAM_APP_FORMAT_VERSION_SIZE, LTFS_INDEX_VERSION_STR); | ||
| parse_vol(t_attr->app_format_ver, strlen(LTFS_INDEX_VERSION_STR), TC_MAM_APP_FORMAT_VERSION_SIZE); | ||
|
|
||
| /* VOLUME LOCKED set */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,8 +62,19 @@ | |
|
|
||
| #include <stdint.h> | ||
| #include <stdbool.h> | ||
| #include <string.h> | ||
| #include <libltfs/ltfs_types.h> | ||
|
|
||
| /* Bounded, always-terminated string copy for the fixed-width identifier | ||
| * fields below; truncation of longer sources is intentional. */ | ||
| static inline void ltfs_string_copy(char *dest, size_t dest_size, const char *src) | ||
| { | ||
| size_t n = strnlen(src, dest_size - 1); | ||
|
|
||
| memcpy(dest, src, n); | ||
| dest[n] = '\0'; | ||
| } | ||
|
Comment on lines
+68
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has the same issue, just a little bit more wide use. Also it adds a third signature to the copy functions of the codebase making it harder for other contributors at knowing which one to use. This can be solved using other more idiomatic approaches like sprintf, or any other. Prefer to use those instead or find a solution that doesn't require a custom copy function. |
||
|
|
||
| #define VENDOR_ID_LENGTH (8) | ||
| #define PRODUCT_ID_LENGTH (16) | ||
| #define PRODUCT_REV_LENGTH (4) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a change done for the use of Cmake, should be moved to that PR since it's also not there and removed from here since it's unrelated.