From 0bcf2c6514189b7b57401f65f8eb0759ab52c1c7 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sat, 4 May 2024 00:25:33 +0200 Subject: [PATCH] const: use arrays of strings Such string is stored directly in '.rodata' section. --- lib/config/config.c | 2 +- lib/device/dev-ext.c | 4 ++-- lib/display/display.c | 4 ++-- lib/format_text/export.c | 5 ++--- lib/metadata/lv_manip.c | 2 +- lib/misc/lvm-signal.c | 2 +- lib/mm/memlock.c | 2 +- lib/report/report.c | 5 ++--- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/config/config.c b/lib/config/config.c index ca37bf686..5dfdee05c 100644 --- a/lib/config/config.c +++ b/lib/config/config.c @@ -35,7 +35,7 @@ #include #include -static const char *_config_source_names[] = { +static const char _config_source_names[][24] = { [CONFIG_UNDEFINED] = "undefined", [CONFIG_FILE] = "file", [CONFIG_MERGED_FILES] = "merged files", diff --git a/lib/device/dev-ext.c b/lib/device/dev-ext.c index 15e9c2b30..8f0f519b5 100644 --- a/lib/device/dev-ext.c +++ b/lib/device/dev-ext.c @@ -20,7 +20,7 @@ #endif struct ext_registry_item { - const char *name; + const char name[16]; struct dev_ext *(* dev_ext_get) (struct device *dev); int (*dev_ext_release) (struct device *dev); }; @@ -90,7 +90,7 @@ static int _dev_ext_release_udev(struct device *dev) #endif } -static struct ext_registry_item _ext_registry[DEV_EXT_NUM] = { +static const struct ext_registry_item _ext_registry[DEV_EXT_NUM] = { EXT_REGISTER(DEV_EXT_NONE, none), EXT_REGISTER(DEV_EXT_UDEV, udev) }; diff --git a/lib/display/display.c b/lib/display/display.c index 262102381..56a0e85b7 100644 --- a/lib/display/display.c +++ b/lib/display/display.c @@ -118,10 +118,10 @@ lock_type_t get_lock_type_from_string(const char *str) return LOCK_TYPE_INVALID; } -static const char *_percent_types[7] = { "NONE", "VG", "FREE", "LV", "PVS", "ORIGIN" }; - const char *get_percent_string(percent_type_t def) { + static const char _percent_types[][8] = { "NONE", "VG", "FREE", "LV", "PVS", "ORIGIN" }; + return _percent_types[def]; } diff --git a/lib/format_text/export.c b/lib/format_text/export.c index fbb8fb1ee..253f0f490 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -224,14 +224,13 @@ static int _out_with_comment_raw(struct formatter *f, */ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) { - static const char *_units[] = { + static const char _units[][16] = { "Kilobytes", "Megabytes", "Gigabytes", "Terabytes", "Petabytes", "Exabytes", - NULL }; int i; @@ -240,7 +239,7 @@ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) /* to convert to K */ d /= 2.0; - for (i = 0; (d > 1024.0) && _units[i]; i++) + for (i = 0; (d > 1024.0) && i < DM_ARRAY_SIZE(_units); ++i) d /= 1024.0; return dm_snprintf(buffer, s, "# %g %s", d, _units[i]) > 0; diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 42a6c0d87..8bf3b1802 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -145,7 +145,7 @@ enum { LV_TYPE_INTEGRITYORIGIN }; -static const char *_lv_type_names[] = { +static const char _lv_type_names[][24] = { [LV_TYPE_UNKNOWN] = "unknown", [LV_TYPE_NONE] = "none", [LV_TYPE_PUBLIC] = "public", diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c index d72417b7e..3cd5f3509 100644 --- a/lib/misc/lvm-signal.c +++ b/lib/misc/lvm-signal.c @@ -29,7 +29,7 @@ static volatile sig_atomic_t _handler_installed = 0; struct ar_sigs { int sig; - const char *name; + const char name[8]; int oldmasked[MAX_SIGINTS]; struct sigaction oldhandler[MAX_SIGINTS]; }; diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c index 815ddfa3a..a2f491426 100644 --- a/lib/mm/memlock.c +++ b/lib/mm/memlock.c @@ -89,7 +89,7 @@ static int _priority; static int _default_priority; /* list of maps, that are unconditionaly ignored */ -static const char * const _ignore_maps[] = { +static const char _ignore_maps[][16] = { "[vdso]", "[vsyscall]", "[vectors]", diff --git a/lib/report/report.c b/lib/report/report.c index da41d1635..126159767 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -252,7 +252,7 @@ static const struct time_prop _time_props[] = { #define TIME_REG_PLURAL_S 0x00000001 /* also recognize plural form with "s" suffix */ struct time_reg { - const char *name; + const char name[16]; const struct time_prop *prop; uint32_t reg_flags; }; @@ -355,7 +355,6 @@ static const struct time_reg _time_reg[] = { {"Nov", TIME_PROP(TIME_MONTH_NOVEMBER), 0}, {"December", TIME_PROP(TIME_MONTH_DECEMBER), 0}, {"Dec", TIME_PROP(TIME_MONTH_DECEMBER), 0}, - {NULL, TIME_PROP(TIME_NULL), 0}, }; struct time_item { @@ -588,7 +587,7 @@ static int _match_time_str(struct dm_list *ti_list, struct time_item *ti) ti->prop = TIME_PROP(TIME_NULL); - for (i = 0; _time_reg[i].name; i++) { + for (i = 0; i < DM_ARRAY_SIZE(_time_reg); ++i) { reg_len = strlen(_time_reg[i].name); if ((ti->len != reg_len) && !((_time_reg[i].reg_flags & TIME_REG_PLURAL_S) && -- 2.43.5