Avoid some hardcoded string sizes

This commit is contained in:
Andrea Mazzoleni 2026-06-25 22:36:47 +02:00
parent 3ce5a5b4e5
commit 42e5e70f4c
4 changed files with 15 additions and 15 deletions

View file

@ -270,7 +270,7 @@ extern int exit_sync_needed;
#define SMARTCTL_FLAG_SELFERROR_LOGGED (1 << 7) /**< The device self-test log contains records of errors. */
/**
* SMART max attribute length.
* SMART max attribute name or value length.
*/
#define SMART_MAX 128
@ -291,7 +291,7 @@ extern int exit_sync_needed;
#define SMART_ATTR_WHEN_FAILED_NEVER 64
struct smart_attr {
char name[128]; /**< SMART attribute name. */
char name[SMART_MAX]; /**< SMART attribute name. */
uint64_t raw; /**< SMART attributes raw. It can be SMART_UNASSIGNED. */
uint64_t norm; /**< SMART attributes normalized. It can be SMART_UNASSIGNED even if raw is not. */
uint64_t worst; /**< SMART attributes worst. It can be SMART_UNASSIGNED even if raw/norm is not. */

View file

@ -583,9 +583,9 @@ static void state_smart_log(devinfo_t* devinfo, double afr)
else if (attr->flags & SMART_ATTR_WHEN_FAILED_NEVER)
when_failed = "never";
char norm[64] = { 0 };
char worst[64] = { 0 };
char thresh[64] = { 0 };
char norm[SMART_MAX] = { 0 };
char worst[SMART_MAX] = { 0 };
char thresh[SMART_MAX] = { 0 };
if (attr->norm != SMART_UNASSIGNED)
snprintf(norm, sizeof(norm), "%" PRIu64, attr->norm);

View file

@ -2588,13 +2588,13 @@ int smartctl_attribute(OS_FILE* f, const char* file, const char* name, struct sm
} else if (smatch(s, "ID#") == 0) {
inside = 1;
} else if (inside) {
char id_name[128] = { 0 };
char type[64] = { 0 };
char updated[64] = { 0 };
char when_failed[64] = { 0 };
char norm[64] = { 0 };
char worst[64] = { 0 };
char thresh[64] = { 0 };
char id_name[SMART_MAX] = { 0 };
char type[SMART_MAX] = { 0 };
char updated[SMART_MAX] = { 0 };
char when_failed[SMART_MAX] = { 0 };
char norm[SMART_MAX] = { 0 };
char worst[SMART_MAX] = { 0 };
char thresh[SMART_MAX] = { 0 };
uint64_t min, max, avg;
int format_minmax = 0;
int format_avg = 0;

View file

@ -3692,9 +3692,9 @@ int ambient_temperature(void)
while ((hwmon_entry = readdir(hwmon_dir)) != NULL) {
char hwmon_name[PATH_MAX];
char value[128];
char name[128];
char label[128];
char value[SMART_MAX];
char name[SMART_MAX];
char label[SMART_MAX];
char* dash;
char* e;
int temp;