hyptop: Replace strncpy() with util_strlcpy()

Ensure that strings are copied correctly by using util_strlcpy() rather
than strncpy().

This fixes the following GCC8 compile warnings:

sd_core.c: In function ‘sd_cpu_new’:
sd_core.c:222:2: warning: ‘strncpy’ specified bound 9 equals destination
size [-Wstringop-truncation]
  strncpy(cpu->id, id, sizeof(cpu->id));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sd_core.c: In function ‘sd_sys_new’:
sd_core.c:254:2: warning: ‘strncpy’ specified bound 9 equals destination
size [-Wstringop-truncation]
  strncpy(sys_new->id, id, sizeof(sys_new->id));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

tbox.c:160:2: warning: ‘strncpy’ specified bound 121 equals destination
size [-Wstringop-truncation]
  strncpy(line_cpy, line, sizeof(line_cpy));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

win_sys.c: In function ‘win_sys_set’:
win_sys.c:329:2: warning: ‘strncpy’ specified bound 9 equals destination
size [-Wstringop-truncation]
  strncpy(l_sys_id, sys_id, sizeof(l_sys_id));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-11-07 11:14:44 +01:00
parent a17b52a043
commit 637750f299
5 changed files with 7 additions and 6 deletions

View File

@@ -17,6 +17,7 @@
#include <sys/types.h>
#include "lib/util_base.h"
#include "lib/util_libc.h"
#include "lib/zt_common.h"
#define G0(x) MAX(0, (s64) (x))

View File

@@ -219,7 +219,7 @@ struct sd_cpu *sd_cpu_new(struct sd_sys *parent, const char *id,
cpu = ht_zalloc(sizeof(*cpu));
cpu->i.parent = parent;
strncpy(cpu->id, id, sizeof(cpu->id));
util_strlcpy(cpu->id, id, sizeof(cpu->id));
cpu->type = l_cpu_type_by_id(type);
cpu->d_cur = &cpu->d1;
cpu->cnt = cnt;
@@ -251,7 +251,7 @@ struct sd_sys *sd_sys_new(struct sd_sys *parent, const char *id)
struct sd_sys *sys_new;
sys_new = ht_zalloc(sizeof(*sys_new));
strncpy(sys_new->id, id, sizeof(sys_new->id));
util_strlcpy(sys_new->id, id, sizeof(sys_new->id));
util_list_init(&sys_new->child_list, struct sd_sys, list);
util_list_init(&sys_new->cpu_list, struct sd_cpu, list);

View File

@@ -47,7 +47,7 @@ static void l_mark_key_add(struct table *t, char *str)
struct table_mark_key *key;
key = ht_zalloc(sizeof(*key));
strncpy(key->str, str, sizeof(key->str));
util_strlcpy(key->str, str, sizeof(key->str));
util_list_add_tail(&t->mark_key_list, key);
}
@@ -617,7 +617,7 @@ void table_row_select_key_get(struct table *t, char str[TABLE_STR_MAX])
struct table_row *row;
row = l_selected_row(t);
strncpy(str, row->entries[0].str, TABLE_STR_MAX);
util_strlcpy(str, row->entries[0].str, TABLE_STR_MAX);
}
/*

View File

@@ -157,7 +157,7 @@ static void l_print_line(const char *line)
char line_cpy[TBOX_MAX_STR + 1];
char *ptr_old, *ptr;
strncpy(line_cpy, line, sizeof(line_cpy));
util_strlcpy(line_cpy, line, sizeof(line_cpy));
ptr_old = ptr = line_cpy;
do {
ptr = strchr(ptr, '\\');

View File

@@ -326,7 +326,7 @@ void win_sys_set(const char *sys_id)
{
if (l_initialized)
table_reset(l_t);
strncpy(l_sys_id, sys_id, sizeof(l_sys_id));
util_strlcpy(l_sys_id, sys_id, sizeof(l_sys_id));
}
/*