Skip to content

Commit 696f67d

Browse files
Copilotprobonopd
andcommitted
Fix remaining compiler warnings in digest.c and appimagetool.c
- Fix sign-conversion warnings in digest.c by casting unsigned long offsets to long before arithmetic - Cast length values to ssize_t when subtracting from bytes_left_this_chunk - Fix format-truncation warning in appimagetool.c by reducing app_name_for_filename buffer size to leave room for suffix - Change sprintf to snprintf for app_name_for_filename to match safer pattern All builds now compile cleanly with -Wall -Wextra -Wconversion -Werror. Co-authored-by: probonopd <[email protected]>
1 parent eee1b87 commit 696f67d

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/appimagetool.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,17 @@ main (int argc, char *argv[])
777777
gchar* arch = getArchName(archs);
778778
fprintf(stderr, "Using architecture %s\n", arch);
779779

780-
char app_name_for_filename[PATH_MAX];
780+
// Reserve space for version, arch, and ".AppImage" suffix (max ~50 chars)
781+
char app_name_for_filename[PATH_MAX - 50];
781782
{
782783
const char* const env_app_name = getenv("APPIMAGETOOL_APP_NAME");
783784
if (env_app_name != NULL) {
784785
fprintf(stderr, "Using user-specified app name: %s\n", env_app_name);
785-
strncpy(app_name_for_filename, env_app_name, PATH_MAX - 1);
786-
app_name_for_filename[PATH_MAX - 1] = '\0';
786+
strncpy(app_name_for_filename, env_app_name, sizeof(app_name_for_filename) - 1);
787+
app_name_for_filename[sizeof(app_name_for_filename) - 1] = '\0';
787788
} else {
788789
const gchar* const desktop_file_app_name = get_desktop_entry(kf, "Name");
789-
sprintf(app_name_for_filename, "%s", desktop_file_app_name);
790+
snprintf(app_name_for_filename, sizeof(app_name_for_filename), "%s", desktop_file_app_name);
790791
replacestr(app_name_for_filename, " ", "_");
791792

792793
if (verbose) {

src/digest.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ bool appimage_type2_digest_md5(const char* path, char* digest) {
5757
}
5858

5959
// check whether there's a section in this chunk that we need to skip
60-
if (digest_md5_offset != 0 && digest_md5_length != 0 && digest_md5_offset - current_position > 0 && digest_md5_offset - current_position < chunk_size) {
61-
ssize_t begin_of_section = (digest_md5_offset - current_position) % chunk_size;
60+
if (digest_md5_offset != 0 && digest_md5_length != 0 && (long)digest_md5_offset - current_position > 0 && (long)digest_md5_offset - current_position < chunk_size) {
61+
ssize_t begin_of_section = ((long)digest_md5_offset - current_position) % chunk_size;
6262
// read chunk before section
6363
fread(buffer, sizeof(char), (size_t) begin_of_section, fp);
6464

6565
bytes_left_this_chunk -= begin_of_section;
66-
bytes_left_this_chunk -= digest_md5_length;
66+
bytes_left_this_chunk -= (ssize_t)digest_md5_length;
6767

6868
// if bytes_left is now < 0, the section exceeds the current chunk
6969
// this amount of bytes needs to be skipped in the future sections
@@ -77,13 +77,13 @@ bool appimage_type2_digest_md5(const char* path, char* digest) {
7777
}
7878

7979
// check whether there's a section in this chunk that we need to skip
80-
if (signature_offset != 0 && signature_length != 0 && signature_offset - current_position > 0 && signature_offset - current_position < chunk_size) {
81-
ssize_t begin_of_section = (signature_offset - current_position) % chunk_size;
80+
if (signature_offset != 0 && signature_length != 0 && (long)signature_offset - current_position > 0 && (long)signature_offset - current_position < chunk_size) {
81+
ssize_t begin_of_section = ((long)signature_offset - current_position) % chunk_size;
8282
// read chunk before section
8383
fread(buffer, sizeof(char), (size_t) begin_of_section, fp);
8484

8585
bytes_left_this_chunk -= begin_of_section;
86-
bytes_left_this_chunk -= signature_length;
86+
bytes_left_this_chunk -= (ssize_t)signature_length;
8787

8888
// if bytes_left is now < 0, the section exceeds the current chunk
8989
// this amount of bytes needs to be skipped in the future sections
@@ -97,13 +97,13 @@ bool appimage_type2_digest_md5(const char* path, char* digest) {
9797
}
9898

9999
// check whether there's a section in this chunk that we need to skip
100-
if (sig_key_offset != 0 && sig_key_length != 0 && sig_key_offset - current_position > 0 && sig_key_offset - current_position < chunk_size) {
101-
ssize_t begin_of_section = (sig_key_offset - current_position) % chunk_size;
100+
if (sig_key_offset != 0 && sig_key_length != 0 && (long)sig_key_offset - current_position > 0 && (long)sig_key_offset - current_position < chunk_size) {
101+
ssize_t begin_of_section = ((long)sig_key_offset - current_position) % chunk_size;
102102
// read chunk before section
103103
fread(buffer, sizeof(char), (size_t) begin_of_section, fp);
104104

105105
bytes_left_this_chunk -= begin_of_section;
106-
bytes_left_this_chunk -= sig_key_length;
106+
bytes_left_this_chunk -= (ssize_t)sig_key_length;
107107

108108
// if bytes_left is now < 0, the section exceeds the current chunk
109109
// this amount of bytes needs to be skipped in the future sections

0 commit comments

Comments
 (0)