From 85fb0ab5c966be4e3da623f1486d4d87f5ab4a76 Mon Sep 17 00:00:00 2001 From: volschin Date: Thu, 2 Apr 2026 17:23:49 +0000 Subject: [PATCH 1/2] fix: correct attribute, format specifiers, const qualifiers, and header guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - nibble_to_ascii: __attribute__((const)) → __attribute__((pure)) since the function reads from a local array (memory beyond its arguments) - flash-ota.c: fix mixed %u/%d for int-typed fw_blocks and block vars, remove unnecessary (unsigned int) casts - Add missing #ifndef header guards to hexdump.h and version.h - Add const qualifier to prog parameter in all syntax() functions and socket_server() for consistency with other read-only string parameters --- flash-hmcfgusb.c | 2 +- flash-hmmoduart.c | 2 +- flash-ota.c | 10 +++++----- hexdump.h | 5 +++++ hmland.c | 4 ++-- hmsniff.c | 2 +- util.c | 2 +- util.h | 2 +- version.h | 5 +++++ 9 files changed, 22 insertions(+), 12 deletions(-) diff --git a/flash-hmcfgusb.c b/flash-hmcfgusb.c index 4751022..ae7361e 100644 --- a/flash-hmcfgusb.c +++ b/flash-hmcfgusb.c @@ -56,7 +56,7 @@ static int parse_hmcfgusb(uint8_t *buf, int buf_len, void *data) return 1; } -void flash_hmcfgusb_syntax(char *prog) +void flash_hmcfgusb_syntax(const char *prog) { fprintf(stderr, "Syntax: %s [options] filename.enc\n\n", prog); fprintf(stderr, "Possible options:\n"); diff --git a/flash-hmmoduart.c b/flash-hmmoduart.c index 8249f89..eb6263d 100644 --- a/flash-hmmoduart.c +++ b/flash-hmmoduart.c @@ -54,7 +54,7 @@ static int parse_hmuartlgw(enum hmuartlgw_dst __attribute__((unused)) dst, uint8 return 1; } -void flash_hmmoduart_syntax(char *prog) +void flash_hmmoduart_syntax(const char *prog) { fprintf(stderr, "Syntax: %s [options] -U /dev/ttyAMA0 filename.eq3\n\n", prog); fprintf(stderr, "Mandatory parameter:\n"); diff --git a/flash-ota.c b/flash-ota.c index 2f28f4b..654f3ee 100644 --- a/flash-ota.c +++ b/flash-ota.c @@ -617,7 +617,7 @@ static int switch_speed(struct hm_dev *dev, struct recv_data *rdata, uint8_t spe return 1; } -void flash_ota_syntax(char *prog) +void flash_ota_syntax(const char *prog) { fprintf(stderr, "Syntax: %s parameters options\n\n", prog); fprintf(stderr, "Mandatory parameters:\n"); @@ -1214,7 +1214,7 @@ int main(int argc, char **argv) if (debug) { printf("\n"); } else { - printf(": %04u/%04u %c", 0u, (unsigned int)fw->fw_blocks, twiddlie[0]); + printf(": %04d/%04d %c", 0, fw->fw_blocks, twiddlie[0]); fflush(stdout); } @@ -1272,15 +1272,15 @@ int main(int argc, char **argv) fprintf(stderr, "\nToo many errors, giving up!\n"); exit(EXIT_FAILURE); } else { - printf("Flashing %d blocks: %04u/%04u %c", fw->fw_blocks, (unsigned int)(block + 1), (unsigned int)fw->fw_blocks, twiddlie[msgnum % sizeof(twiddlie)]); + printf("Flashing %d blocks: %04d/%04d %c", fw->fw_blocks, block + 1, fw->fw_blocks, twiddlie[msgnum % sizeof(twiddlie)]); } } msgnum++; if (!debug) { - printf("\b\b\b\b\b\b\b\b\b\b\b%04u/%04u %c", - (unsigned int)(block + 1), (unsigned int)fw->fw_blocks, twiddlie[msgnum % sizeof(twiddlie)]); + printf("\b\b\b\b\b\b\b\b\b\b\b%04d/%04d %c", + block + 1, fw->fw_blocks, twiddlie[msgnum % sizeof(twiddlie)]); fflush(stdout); } } while((pos - &(fw->fw[block][2])) < len); diff --git a/hexdump.h b/hexdump.h index 127bfb0..bc0db2a 100644 --- a/hexdump.h +++ b/hexdump.h @@ -1,3 +1,6 @@ +#ifndef HEXDUMP_H +#define HEXDUMP_H + /* simple hexdumper * * Copyright (c) 2004-2016 Michael Gernoth @@ -56,3 +59,5 @@ static void hexdump(const unsigned char *buf, int len, const char *prefix) asciishow(buf+i-(i%16), (i%16)); fprintf(stderr, "\n"); } + +#endif /* HEXDUMP_H */ diff --git a/hmland.c b/hmland.c index f6ef096..5dc9146 100644 --- a/hmland.c +++ b/hmland.c @@ -638,7 +638,7 @@ __attribute__((noreturn)) void sigterm_handler(int __attribute__((unused)) sig) #define FLAG_DAEMON (1 << 0) #define FLAG_PID_FILE (1 << 1) -static int socket_server(char *iface, int port, int flags) +static int socket_server(const char *iface, int port, int flags) { struct sigaction sact; struct sockaddr_in sin; @@ -804,7 +804,7 @@ static int interactive_server(int flags) return EXIT_SUCCESS; } -void hmlan_syntax(char *prog) +void hmlan_syntax(const char *prog) { fprintf(stderr, "Syntax: %s options\n\n", prog); fprintf(stderr, "Possible options:\n"); diff --git a/hmsniff.c b/hmsniff.c index c1c1f7a..5b4130b 100644 --- a/hmsniff.c +++ b/hmsniff.c @@ -256,7 +256,7 @@ static int parse_hmuartlgw(enum hmuartlgw_dst dst, uint8_t *buf, int buf_len, vo return 1; } -void hmsniff_syntax(char *prog) +void hmsniff_syntax(const char *prog) { fprintf(stderr, "Syntax: %s options\n\n", prog); fprintf(stderr, "Possible options:\n"); diff --git a/util.c b/util.c index d22afe1..0b3251a 100644 --- a/util.c +++ b/util.c @@ -48,7 +48,7 @@ __attribute__((const)) int validate_nibble(uint8_t a) return 0; } -__attribute__((const)) char nibble_to_ascii(uint8_t n) +__attribute__((pure)) char nibble_to_ascii(uint8_t n) { const uint8_t nibble[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; diff --git a/util.h b/util.h index b78c7d5..fa27779 100644 --- a/util.h +++ b/util.h @@ -26,6 +26,6 @@ __attribute__((const)) uint8_t ascii_to_nibble(uint8_t a); __attribute__((const)) int validate_nibble(uint8_t a); -__attribute__((const)) char nibble_to_ascii(uint8_t n); +__attribute__((pure)) char nibble_to_ascii(uint8_t n); #endif /* UTIL_H */ diff --git a/version.h b/version.h index cd8d17a..0a928da 100644 --- a/version.h +++ b/version.h @@ -1 +1,6 @@ +#ifndef VERSION_H +#define VERSION_H + #define VERSION "0.103-git" + +#endif /* VERSION_H */ From 0fb1fce56454a711b5eb519c8581b1f8fc25bf2a Mon Sep 17 00:00:00 2001 From: "St. Veit" Date: Thu, 2 Apr 2026 19:29:19 +0200 Subject: [PATCH 2/2] Update version number to 1.0.1 --- version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.h b/version.h index 0a928da..7c1f80a 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #ifndef VERSION_H #define VERSION_H -#define VERSION "0.103-git" +#define VERSION "1.0.1" #endif /* VERSION_H */