Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ 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}"
AM_CFLAGS="${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}"

if test "x$use_fast" = "xyes"
then
Expand Down Expand Up @@ -529,7 +529,7 @@ then
SSE42=yes
fi

if test ${GCC_VERSION_MAJOR} -ge 8 -a ${GCC_VERSION_MINOR} -ge 0 -a "x$warning_as_error" = "xyes"
if test ${GCC_VERSION_MAJOR} -ge 8
then
AM_CFLAGS="${AM_CFLAGS} -Wno-stringop-truncation"
fi
Expand Down
4 changes: 2 additions & 2 deletions src/libltfs/arch/arch_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void show_runtime_system_info(void)
ltfsmsg(LTFS_WARN, 17086W);
} else {
memset(kernel_version, 0, sizeof(kernel_version));
read(fd, kernel_version, sizeof(kernel_version));
(void)!read(fd, kernel_version, sizeof(kernel_version) - 1);
if((tmp = strchr(kernel_version, '\n')) != NULL)
*tmp = '\0';

Expand Down Expand Up @@ -118,7 +118,7 @@ void show_runtime_system_info(void)
} else {
if (fstat(fd, &stat_rel) != -1 && S_ISREG(stat_rel.st_mode)) {
memset(destribution, 0, sizeof(destribution));
read(fd, destribution, sizeof(destribution));
(void)!read(fd, destribution, sizeof(destribution) - 1);
if((tmp = strchr(destribution, '\n')) != NULL)
*tmp = '\0';
ltfsmsg(LTFS_INFO, 17089I, destribution);
Expand Down
12 changes: 7 additions & 5 deletions src/libltfs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ uint64_t fs_allocate_uid(struct ltfs_index *idx)
int fs_dentry_lookup(struct dentry *dentry, char **name)
{
char **dentry_names = NULL, *tmp_name = NULL;
int i, names, namelen = 0, ret = 0;
int ret = 0;
ssize_t i;
size_t names, namelen = 0;
Comment on lines +429 to +431

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What warning was this fixing when compiling before? Can you please share details about the warning and specific platform? Thanks

@matejk matejk Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many warnings appear only with a higher -O level. This one is -Walloc-size-larger-than, reported by gcc 15 (Ubuntu 25.10 and 26.04) with --enable-fast (-O2); clang does not report it.

namelen + names is int, and gcc's range analysis finds it can be negative; converted to calloc's size_t argument that becomes ~2^64. Fixed by making names/namelen size_t.

struct dentry *d, *parent;
const char *lookup_name;

Expand All @@ -447,7 +449,7 @@ int fs_dentry_lookup(struct dentry *dentry, char **name)

d = dentry;
parent = d->parent;
for (i=names-1; i>=0; --i) {
for (i = (ssize_t)names - 1; i >= 0; --i) {
if (parent)
acquireread_mrsw(&parent->contents_lock);

Expand Down Expand Up @@ -483,9 +485,9 @@ int fs_dentry_lookup(struct dentry *dentry, char **name)
goto out;
}

for (namelen=0, i=0; i<names; ++i) {
for (namelen=0, i=0; i < (ssize_t)names; ++i) {
arch_strcat(tmp_name,tmp_len, dentry_names[i]);
if (i > 0 && i < names-1)
if (i > 0 && i < (ssize_t)names-1)
arch_strcat(tmp_name, tmp_len, "/");
}

Expand All @@ -496,7 +498,7 @@ int fs_dentry_lookup(struct dentry *dentry, char **name)
if (ret != 0 && tmp_name)
free(tmp_name);
if (dentry_names) { /* BEAM: constant condition - dentry_names has always non-zero value here. */
while (--names >= 0)
while (names-- > 0)
if (dentry_names[names])
free(dentry_names[names]);
free(dentry_names);
Expand Down
2 changes: 1 addition & 1 deletion src/libltfs/ltfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4404,7 +4404,7 @@ void ltfs_enable_livelink_mode(struct ltfs_volume *vol)
*/
int ltfs_profiler_set(uint64_t source, struct ltfs_volume *vol)
{
int ret, ret_save = 0;
int ret = 0, ret_save = 0;

if (vol->iosched_handle) {
if (source & PROF_IOSCHED) {
Expand Down
3 changes: 2 additions & 1 deletion src/libltfs/ltfs_fsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,7 +2000,8 @@ int ltfs_fsops_readlink_path(const char *path, char *buf, size_t size, ltfs_file

int ltfs_fsops_target_absolute_path(const char* link, const char* target, char* buf, size_t size )
{
char *work_buf, *target_buf, *temp_buf, *token, *next_token; /* work buffers for string */
char *work_buf, *target_buf, *token, *next_token; /* work buffers for string */
const char *temp_buf;
int len=0, len2=0; /* work variables for string length */

CHECK_ARG_NULL(link, -LTFS_NULL_ARG);
Expand Down
20 changes: 10 additions & 10 deletions src/libltfs/ltfstrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,37 +694,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));
(void)!arch_write(fd, trc_header, sizeof(struct trace_header));
(void)!arch_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);
(void)!arch_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));
(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));
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));
(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));
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);
(void)!arch_write(fd, fsitem->fn_entry->entries, FS_FN_TRACE_SIZE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a little comment on these changes, I suggested this for an idiomatic approach of GCC shenanigans to suppress a warning, but making some tests I see no warnings with the original way this was done, do you have more info about the specific warnings and system you saw a warning being raised?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning is -Wunused-result on write(): glibc marks it warn_unused_result only when _FORTIFY_SOURCE is set, and configure sets -D_FORTIFY_SOURCE=2 only with --enable-fast (-O2). The default ./configure builds with -O0 -D_FORTIFY_SOURCE=0, where nothing is reported — most likely the difference.

Reproduced with --enable-fast on gcc 15.2 (Ubuntu 25.10 and 26.04): 9 warnings at ltfstrace.c:697–722. A plain (void) cast does not silence it on gcc; (void)! does. clang does not report these.

Should this be commented at the call sites for future readers?

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);
(void)!arch_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);
(void)!arch_write(fd, tailq_item->fn_entry->entries, ADMIN_FN_TRACE_SIZE);
releaseread_mrsw(&tailq_item->fn_entry->trace_lock);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libltfs/tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,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;

Expand Down
5 changes: 3 additions & 2 deletions src/libltfs/xml_writer_libltfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,9 @@ int xml_schema_to_tape(char *reason, struct ltfs_volume *vol)
}

/* Generate the Index. */
asprintf(&creator, "%s - %s", vol->creator, reason);
if (creator) {
if (asprintf(&creator, "%s - %s", vol->creator, reason) < 0)
creator = NULL;
if (creator != NULL) {
ret = _xml_write_schema(writer, creator, vol->index);
if (ret < 0) {
ltfsmsg(LTFS_ERR, 17055E, ret);
Expand Down
5 changes: 4 additions & 1 deletion src/tape_drivers/generic/itdtimg/itdtimg_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,10 @@ int itdtimage_read_attribute(void *vstate, const tape_partition_t part, const ui
return -EDEV_HARDWARE_ERROR;
}

fread(buf, 1, data2ReadFromFile, state->img_file);
if (fread(buf, 1, data2ReadFromFile, state->img_file) != data2ReadFromFile) {
ltfsmsg(LTFS_ERR, 31002E, (long long)attrLength, state->filename, offset);
return -EDEV_HARDWARE_ERROR;
}
return DEVICE_GOOD;
}

Expand Down
12 changes: 8 additions & 4 deletions src/tape_drivers/linux/sg/sg_scsi_tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ static int _inquiry_low(struct sg_tape *device, uint8_t page, unsigned char *buf
int sg_get_drive_identifier(struct sg_tape *device, scsi_device_identifier *id_data)
{
int ret;
size_t serial_len;
unsigned char inquiry_buf[MAX_INQ_LEN];

CHECK_ARG_NULL(id_data, -LTFS_NULL_ARG);
Expand All @@ -466,17 +467,20 @@ int sg_get_drive_identifier(struct sg_tape *device, scsi_device_identifier *id_d
return -EDEV_DEVICE_UNSUPPORTABLE;
}

strncpy(id_data->vendor_id, (char*)(&(inquiry_buf[8])), VENDOR_ID_LENGTH);
strncpy(id_data->product_id, (char*)(&(inquiry_buf[16])), PRODUCT_ID_LENGTH);
strncpy(id_data->product_rev, (char*)(&(inquiry_buf[32])), PRODUCT_REV_LENGTH);
memcpy(id_data->vendor_id, &inquiry_buf[8], VENDOR_ID_LENGTH);
memcpy(id_data->product_id, &inquiry_buf[16], PRODUCT_ID_LENGTH);
memcpy(id_data->product_rev, &inquiry_buf[32], PRODUCT_REV_LENGTH);

ret = _inquiry_low(device, 0x80, inquiry_buf, MAX_INQ_LEN);
if( ret < 0 ) {
ltfsmsg(LTFS_INFO, 30206I, ret);
return ret;
}

strncpy(id_data->unit_serial, (char*)(&(inquiry_buf[4])), inquiry_buf[3]);
serial_len = inquiry_buf[3];
if (serial_len > UNIT_SERIAL_LENGTH)
serial_len = UNIT_SERIAL_LENGTH;
memcpy(id_data->unit_serial, &inquiry_buf[4], serial_len);

return 0;
}
45 changes: 22 additions & 23 deletions src/tape_drivers/linux/sg/sg_tape.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static int _get_dump(struct sg_data *priv, char *fname)
long long data_length, buf_offset;
int dumpfd = -1;
int transfer_size, num_transfers, excess_transfer;
int i, bytes;
int bytes;
unsigned char cap_buf[DUMP_HEADER_SIZE];
unsigned char *dump_buf;
int buf_id;
Expand Down Expand Up @@ -334,14 +334,11 @@ static int _get_dump(struct sg_data *priv, char *fname)

/* start to transfer data */
buf_offset = 0;
i = 0;
ltfsmsg(LTFS_DEBUG, 30257D);
while(num_transfers)
{
int length;

i++;

/* Allocation Length is transfer_size or excess_transfer*/
if(excess_transfer && num_transfers == 1)
length = excess_transfer;
Expand Down Expand Up @@ -531,8 +528,10 @@ static int _raw_open(struct sg_data *priv)
priv->dev.fd = -1;
return -EDEV_DEVICE_UNOPENABLE; /* Unexpected device is opened */
}
} else
strncpy(priv->drive_serial, id_data.unit_serial, sizeof(priv->drive_serial) - 1);
} else {
snprintf(priv->drive_serial, sizeof(priv->drive_serial), "%.*s",
(int)sizeof(priv->drive_serial) - 1, id_data.unit_serial);
}

/* Get SCSI ID */
if (! ioctl(priv->dev.fd, SG_GET_SCSI_ID, &scsi_id)) {
Expand All @@ -550,12 +549,12 @@ static int _raw_open(struct sg_data *priv)
ltfsmsg(LTFS_INFO, 30214I, id_data.product_rev);
ltfsmsg(LTFS_INFO, 30215I, priv->drive_serial);

strncpy(priv->info.name, priv->devname, TAPE_DEVNAME_LEN_MAX + 1);
strncpy(priv->info.vendor, id_data.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1);
strncpy(priv->info.model, id_data.product_id, TAPE_MODEL_NAME_LEN_MAX + 1);
strncpy(priv->info.serial_number, id_data.unit_serial, TAPE_SERIAL_LEN_MAX + 1);
strncpy(priv->info.product_rev, id_data.product_rev, PRODUCT_REV_LENGTH + 1);
strncpy(priv->info.product_name, _generate_product_name(id_data.product_id), PRODUCT_NAME_LENGTH + 1);
snprintf(priv->info.name, sizeof(priv->info.name), "%.*s", (int)sizeof(priv->info.name) - 1, priv->devname);
snprintf(priv->info.vendor, sizeof(priv->info.vendor), "%.*s", (int)sizeof(priv->info.vendor) - 1, id_data.vendor_id);
snprintf(priv->info.model, sizeof(priv->info.model), "%.*s", (int)sizeof(priv->info.model) - 1, id_data.product_id);
snprintf(priv->info.serial_number, sizeof(priv->info.serial_number), "%.*s", (int)sizeof(priv->info.serial_number) - 1, id_data.unit_serial);
snprintf(priv->info.product_rev, sizeof(priv->info.product_rev), "%.*s", (int)sizeof(priv->info.product_rev) - 1, id_data.product_rev);
snprintf(priv->info.product_name, sizeof(priv->info.product_name), "%.*s", (int)sizeof(priv->info.product_name) - 1, _generate_product_name(id_data.product_id));

return 0;
}
Expand Down Expand Up @@ -1646,9 +1645,9 @@ int sg_inquiry(void *device, struct tc_inq *inq)
return ret;

memset(inq, 0, sizeof(struct tc_inq));
strncpy((char*)inq->vid, (char*)inq_page.data + 8, VENDOR_ID_LENGTH);
strncpy((char*)inq->pid, (char*)inq_page.data + 16, PRODUCT_ID_LENGTH);
strncpy((char*)inq->revision, (char*)inq_page.data + 32, PRODUCT_REV_LENGTH);
memcpy(inq->vid, inq_page.data + 8, VENDOR_ID_LENGTH);
memcpy(inq->pid, inq_page.data + 16, PRODUCT_ID_LENGTH);
memcpy(inq->revision, inq_page.data + 32, PRODUCT_REV_LENGTH);

inq->devicetype = priv->drive_type;

Expand All @@ -1657,7 +1656,7 @@ int sg_inquiry(void *device, struct tc_inq *inq)
else
vendor_length = 20;

strncpy((char*)inq->vendor, (char*)inq_page.data + 36, vendor_length);
memcpy(inq->vendor, inq_page.data + 36, vendor_length);
inq->vendor[vendor_length] = '\0';

return ret;
Expand Down Expand Up @@ -1710,7 +1709,7 @@ int sg_test_unit_ready(void *device)
case -EDEV_NEED_INITIALIZE:
case -EDEV_CONFIGURE_CHANGED:
print_msg = false;
/* fall throuh */
/* fall through */
case -EDEV_NO_MEDIUM:
case -EDEV_BECOMING_READY:
case -EDEV_MEDIUM_MAY_BE_CHANGED:
Expand Down Expand Up @@ -4432,12 +4431,12 @@ int sg_get_device_list(struct tc_drive_info *buf, int count)
}

if (found < count && buf) {
strncpy(buf[found].name, devname, TAPE_DEVNAME_LEN_MAX + 1);
strncpy(buf[found].vendor, identifier.vendor_id, TAPE_VENDOR_NAME_LEN_MAX + 1);
strncpy(buf[found].model, identifier.product_id, TAPE_MODEL_NAME_LEN_MAX + 1);
strncpy(buf[found].serial_number, identifier.unit_serial, TAPE_SERIAL_LEN_MAX + 1);
strncpy(buf[found].product_rev, identifier.product_rev, PRODUCT_REV_LENGTH + 1);
strncpy(buf[found].product_name, _generate_product_name(identifier.product_id), PRODUCT_NAME_LENGTH + 1);
snprintf(buf[found].name, sizeof(buf[found].name), "%.*s", (int)sizeof(buf[found].name) - 1, devname);
snprintf(buf[found].vendor, sizeof(buf[found].vendor), "%.*s", (int)sizeof(buf[found].vendor) - 1, identifier.vendor_id);
snprintf(buf[found].model, sizeof(buf[found].model), "%.*s", (int)sizeof(buf[found].model) - 1, identifier.product_id);
snprintf(buf[found].serial_number, sizeof(buf[found].serial_number), "%.*s", (int)sizeof(buf[found].serial_number) - 1, identifier.unit_serial);
snprintf(buf[found].product_rev, sizeof(buf[found].product_rev), "%.*s", (int)sizeof(buf[found].product_rev) - 1, identifier.product_rev);
snprintf(buf[found].product_name, sizeof(buf[found].product_name), "%.*s", (int)sizeof(buf[found].product_name) - 1, _generate_product_name(identifier.product_id));

if (! ioctl(dev.fd, SG_GET_SCSI_ID, &scsi_id)) {
buf[found].host = scsi_id.host_no;
Expand Down
Loading