aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhwspeedy <ns@bigbear.dk>2024-03-15 01:43:07 +0100
committerhwspeedy <ns@bigbear.dk>2024-03-15 01:43:07 +0100
commitf88fd2c25040a784196d270917a5d6e049d5d614 (patch)
tree1d6516b49354d66b8338e305ff98766b232b26ee
parent3e5d70b7d9e1555e516547c7d6d56b712ea4ed15 (diff)
FIX GCC warnings strncpy
-rw-r--r--deps/sysobj_early/src/nice_name.c28
-rw-r--r--deps/sysobj_early/src/util_ids.c4
-rw-r--r--hardinfo2/x_util.c6
3 files changed, 23 insertions, 15 deletions
diff --git a/deps/sysobj_early/src/nice_name.c b/deps/sysobj_early/src/nice_name.c
index e5e15a46..fdb4557c 100644
--- a/deps/sysobj_early/src/nice_name.c
+++ b/deps/sysobj_early/src/nice_name.c
@@ -34,11 +34,15 @@ gboolean str_shorten(gchar *str, const gchar *find, const gchar *replace) {
long unsigned lr = strlen(replace);
gchar *p = strstr(str, find);
if (p) {
- if (lr > lf) lr = lf;
- gchar *buff = g_strnfill(lf, ' ');
- strncpy(buff, replace, lr);
- strncpy(p, buff, lf);
- g_free(buff);
+ if(lr==lf){
+ strncpy(p, replace, lf);
+ } else {
+ if (lr > lf) lr = lf;
+ gchar *buff = g_strnfill(lf, ' ');
+ if(lr) strncpy(buff, replace, lr);
+ strncpy(p, buff, lf);
+ g_free(buff);
+ }
return TRUE;
}
return FALSE;
@@ -50,11 +54,15 @@ gboolean str_shorten_anycase(gchar *str, const gchar *find, const gchar *replace
long unsigned lr = strlen(replace);
gchar *p = strcasestr(str, find);
if (p) {
- if (lr > lf) lr = lf;
- gchar *buff = g_strnfill(lf, ' ');
- strncpy(buff, replace, lr);
- strncpy(p, buff, lf);
- g_free(buff);
+ if(lr==lf){
+ strncpy(p, replace, lf);
+ } else {
+ if (lr > lf) lr = lf;
+ gchar *buff = g_strnfill(lf, ' ');
+ if(lr) strncpy(buff, replace, lr);
+ strncpy(p, buff, lf);
+ g_free(buff);
+ }
return TRUE;
}
return FALSE;
diff --git a/deps/sysobj_early/src/util_ids.c b/deps/sysobj_early/src/util_ids.c
index 197b1ed3..9546a8b7 100644
--- a/deps/sysobj_early/src/util_ids.c
+++ b/deps/sysobj_early/src/util_ids.c
@@ -243,7 +243,7 @@ GSList *ids_file_all_get_all(const gchar *file, split_loc_function split_loc_fun
ids_query_result *working = g_new0(ids_query_result, 1);
gchar **qparts = g_new0(gchar*, IDS_LOOKUP_MAX_DEPTH + 1);
for(tabs = IDS_LOOKUP_MAX_DEPTH-1; tabs>=0; tabs--)
- qparts[tabs] = g_malloc0(IDS_LOOKUP_BUFF_SIZE);
+ qparts[tabs] = g_malloc0(IDS_LOOKUP_BUFF_SIZE+1);
tabs = 0;
if (!split_loc_func) split_loc_func = split_loc_default;
@@ -290,7 +290,7 @@ GSList *ids_file_all_get_all(const gchar *file, split_loc_function split_loc_fun
// now p = id, name = name
// ids_msg("p: %s -- name: %s", p, name);
- strncpy(qparts[tabs], p, IDS_LOOKUP_BUFF_SIZE-1);
+ strncpy(qparts[tabs], p, IDS_LOOKUP_BUFF_SIZE);
ids_query_result_set_str(working, tabs, name);
if (tabs < tabs_last)
for(;tabs_last > tabs; tabs_last--) {
diff --git a/hardinfo2/x_util.c b/hardinfo2/x_util.c
index 2a7febb4..95e3274d 100644
--- a/hardinfo2/x_util.c
+++ b/hardinfo2/x_util.c
@@ -156,7 +156,7 @@ gboolean fill_xrr_info(xrr_info *xrr) {
x_screen ts;
x_output to;
- char output_id[128];
+ char output_id[64];
char status[128];
char alist[512];
@@ -195,7 +195,7 @@ gboolean fill_xrr_info(xrr_info *xrr) {
/* looking for:
* <output_id> (connected|disconnected|unknown connection) (primary|?) <%dx%d+%d+%d> (attribute_list) mm x mm
*/
- ec = sscanf(p, "%127s %127[^(](%511[^)]", output_id, status, alist);
+ ec = sscanf(p, "%63s %127[^(](%511[^)]", output_id, status, alist);
if (ec == 3) {
int is_output = 0, found_rect = 0, n = 0;
gchar **ot = g_strsplit(status, " ", 0);
@@ -228,7 +228,7 @@ gboolean fill_xrr_info(xrr_info *xrr) {
}
g_strfreev(ot);
if (is_output) {
- strncpy(to.name, output_id, 63);
+ strncpy(to.name, output_id, 64);
xrr->output_count++;
if (xrr->outputs == NULL)
xrr->outputs = malloc(xrr->output_count * sizeof(x_output));