strncpy, snprintf and vsnprintf changed to strncpyz, snprintfz and vsnprintfz. And sometimes they are not necessary.
Frederico Lamberti Pissarra committed
May 9, 2016 at 00:26 UTC
acc53a9ac567a1596a000e8703398d891e4f3bc1
28 files changed
+168
-183
src/apps_plugin.c
+25
-28
@@ -219,7 +219,7 @@ long get_system_cpus(void) {
219
int processors = 0;
220
221
char filename[FILENAME_MAX + 1];
222
- snprintf(filename, FILENAME_MAX, "%s/proc/stat", host_prefix);
222
+ snprintfz(filename, FILENAME_MAX, "%s/proc/stat", host_prefix);
223
224
ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
225
if(!ff) return 1;
@@ -248,7 +248,7 @@ long get_system_pid_max(void) {
248
long mpid = 32768;
249
250
char filename[FILENAME_MAX + 1];
251
- snprintf(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", host_prefix);
251
+ snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", host_prefix);
252
ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
253
if(!ff) return mpid;
254
@@ -373,18 +373,18 @@ struct target *get_users_target(uid_t uid)
373
return NULL;
374
}
375
376
- snprintf(w->compare, MAX_COMPARE_NAME, "%d", uid);
376
+ snprintfz(w->compare, MAX_COMPARE_NAME, "%d", uid);
377
w->comparehash = simple_hash(w->compare);
378
w->comparelen = strlen(w->compare);
379
380
- snprintf(w->id, MAX_NAME, "%d", uid);
380
+ snprintfz(w->id, MAX_NAME, "%d", uid);
381
w->idhash = simple_hash(w->id);
382
383
struct passwd *pw = getpwuid(uid);
384
if(!pw)
385
- snprintf(w->name, MAX_NAME, "%d", uid);
385
+ snprintfz(w->name, MAX_NAME, "%d", uid);
386
else
387
- snprintf(w->name, MAX_NAME, "%s", pw->pw_name);
387
+ snprintfz(w->name, MAX_NAME, "%s", pw->pw_name);
388
389
netdata_fix_chart_name(w->name);
390
@@ -411,18 +411,18 @@ struct target *get_groups_target(gid_t gid)
411
return NULL;
412
}
413
414
- snprintf(w->compare, MAX_COMPARE_NAME, "%d", gid);
414
+ snprintfz(w->compare, MAX_COMPARE_NAME, "%d", gid);
415
w->comparehash = simple_hash(w->compare);
416
w->comparelen = strlen(w->compare);
417
418
- snprintf(w->id, MAX_NAME, "%d", gid);
418
+ snprintfz(w->id, MAX_NAME, "%d", gid);
419
w->idhash = simple_hash(w->id);
420
421
struct group *gr = getgrgid(gid);
422
if(!gr)
423
- snprintf(w->name, MAX_NAME, "%d", gid);
423
+ snprintfz(w->name, MAX_NAME, "%d", gid);
424
else
425
- snprintf(w->name, MAX_NAME, "%s", gr->gr_name);
425
+ snprintfz(w->name, MAX_NAME, "%s", gr->gr_name);
426
427
netdata_fix_chart_name(w->name);
428
@@ -464,12 +464,12 @@ struct target *get_apps_groups_target(const char *id, struct target *target)
464
return NULL;
465
}
466
467
- strncpy(w->id, nid, MAX_NAME);
467
+ strncpyz(w->id, nid, MAX_NAME);
468
w->idhash = simple_hash(w->id);
469
470
- strncpy(w->name, nid, MAX_NAME);
470
+ strncpyz(w->name, nid, MAX_NAME);
471
472
- strncpy(w->compare, nid, MAX_COMPARE_NAME);
472
+ strncpyz(w->compare, nid, MAX_COMPARE_NAME);
473
int len = strlen(w->compare);
474
if(w->compare[len - 1] == '*') {
475
w->compare[len - 1] = '\0';
@@ -507,7 +507,7 @@ int read_apps_groups_conf(const char *name)
507
{
508
char filename[FILENAME_MAX + 1];
509
510
- snprintf(filename, FILENAME_MAX, "%s/apps_%s.conf", config_dir, name);
510
+ snprintfz(filename, FILENAME_MAX, "%s/apps_%s.conf", config_dir, name);
511
512
if(unlikely(debug))
513
fprintf(stderr, "apps.plugin: process groups file: '%s'\n", filename);
@@ -559,8 +559,7 @@ int read_apps_groups_conf(const char *name)
559
t++;
560
}
561
562
- strncpy(w->name, t, MAX_NAME);
563
- w->name[MAX_NAME] = '\0';
562
+ strncpyz(w->name, t, MAX_NAME);
563
w->hidden = thidden;
564
w->debug = tdebug;
565
@@ -582,7 +581,7 @@ int read_apps_groups_conf(const char *name)
581
if(!apps_groups_default_target)
582
error("Cannot create default target");
583
else
585
- strncpy(apps_groups_default_target->name, "other", MAX_NAME);
584
+ strncpyz(apps_groups_default_target->name, "other", MAX_NAME);
585
586
return 0;
587
}
@@ -772,7 +771,7 @@ void del_pid_entry(pid_t pid)
771
772
int read_proc_pid_cmdline(struct pid_stat *p) {
773
char filename[FILENAME_MAX + 1];
775
- snprintf(filename, FILENAME_MAX, "%s/proc/%d/cmdline", host_prefix, p->pid);
774
+ snprintfz(filename, FILENAME_MAX, "%s/proc/%d/cmdline", host_prefix, p->pid);
775
776
int fd = open(filename, O_RDONLY, 0666);
777
if(unlikely(fd == -1)) return 1;
@@ -782,8 +781,7 @@ int read_proc_pid_cmdline(struct pid_stat *p) {
781
782
if(bytes <= 0) {
783
// copy the command to the command line
785
- strncpy(p->cmdline, p->comm, MAX_CMDLINE);
786
- p->cmdline[MAX_CMDLINE] = '\0';
784
+ strncpyz(p->cmdline, p->comm, MAX_CMDLINE);
785
return 0;
786
}
787
@@ -800,7 +798,7 @@ int read_proc_pid_cmdline(struct pid_stat *p) {
798
int read_proc_pid_ownership(struct pid_stat *p) {
799
char filename[FILENAME_MAX + 1];
800
803
- snprintf(filename, FILENAME_MAX, "%s/proc/%d", host_prefix, p->pid);
801
+ snprintfz(filename, FILENAME_MAX, "%s/proc/%d", host_prefix, p->pid);
802
803
// ----------------------------------------
804
// read uid and gid
@@ -820,7 +818,7 @@ int read_proc_pid_stat(struct pid_stat *p) {
818
819
char filename[FILENAME_MAX + 1];
820
823
- snprintf(filename, FILENAME_MAX, "%s/proc/%d/stat", host_prefix, p->pid);
821
+ snprintfz(filename, FILENAME_MAX, "%s/proc/%d/stat", host_prefix, p->pid);
822
823
// ----------------------------------------
824
@@ -842,8 +840,7 @@ int read_proc_pid_stat(struct pid_stat *p) {
840
841
// parse the process name
842
unsigned int i = 0;
845
- strncpy(p->comm, procfile_lineword(ff, 0, 1), MAX_COMPARE_NAME);
846
- p->comm[MAX_COMPARE_NAME] = '\0';
843
+ strncpyz(p->comm, procfile_lineword(ff, 0, 1), MAX_COMPARE_NAME);
844
845
// p->pid = atol(procfile_lineword(ff, 0, 0+i));
846
// comm is at 1
@@ -902,7 +899,7 @@ int read_proc_pid_statm(struct pid_stat *p) {
899
900
char filename[FILENAME_MAX + 1];
901
905
- snprintf(filename, FILENAME_MAX, "%s/proc/%d/statm", host_prefix, p->pid);
902
+ snprintfz(filename, FILENAME_MAX, "%s/proc/%d/statm", host_prefix, p->pid);
903
904
ff = procfile_reopen(ff, filename, NULL, PROCFILE_FLAG_NO_ERROR_ON_FILE_IO);
905
if(!ff) return 1;
@@ -932,7 +929,7 @@ int read_proc_pid_io(struct pid_stat *p) {
929
930
char filename[FILENAME_MAX + 1];
931
935
- snprintf(filename, FILENAME_MAX, "%s/proc/%d/io", host_prefix, p->pid);
932
+ snprintfz(filename, FILENAME_MAX, "%s/proc/%d/io", host_prefix, p->pid);
933
934
ff = procfile_reopen(ff, filename, NULL, PROCFILE_FLAG_NO_ERROR_ON_FILE_IO);
935
if(!ff) return 1;
@@ -1187,7 +1184,7 @@ int file_descriptor_find_or_add(const char *name)
1184
int read_pid_file_descriptors(struct pid_stat *p) {
1185
char dirname[FILENAME_MAX+1];
1186
1190
- snprintf(dirname, FILENAME_MAX, "%s/proc/%d/fd", host_prefix, p->pid);
1187
+ snprintfz(dirname, FILENAME_MAX, "%s/proc/%d/fd", host_prefix, p->pid);
1188
DIR *fds = opendir(dirname);
1189
if(fds) {
1190
int c;
@@ -1280,7 +1277,7 @@ int collect_data_for_all_processes_from_proc(void)
1277
{
1278
char dirname[FILENAME_MAX + 1];
1279
1283
- snprintf(dirname, FILENAME_MAX, "%s/proc", host_prefix);
1280
+ snprintfz(dirname, FILENAME_MAX, "%s/proc", host_prefix);
1281
DIR *dir = opendir(dirname);
1282
if(!dir) return 0;
1283
src/main.c
+3
-4
@@ -241,8 +241,7 @@ int main(int argc, char **argv)
241
else if(strcmp(argv[i], "-nodaemon") == 0 || strcmp(argv[i], "-nd") == 0) dont_fork = 1;
242
else if(strcmp(argv[i], "-pidfile") == 0 && (i+1) < argc) {
243
i++;
244
- strncpy(pidfile, argv[i], FILENAME_MAX);
245
- pidfile[FILENAME_MAX] = '\0';
244
+ strncpyz(pidfile, argv[i], FILENAME_MAX);
245
}
246
else if(strcmp(argv[i], "--unittest") == 0) {
247
rrd_update_every = 1;
@@ -403,8 +402,8 @@ int main(int argc, char **argv)
402
403
// let the plugins know the min update_every
404
{
406
- char buf[50];
407
- snprintf(buf, 50, "%d", rrd_update_every);
405
+ char buf[51];
406
+ snprintfz(buf, 50, "%d", rrd_update_every);
407
setenv("NETDATA_UPDATE_EVERY", buf, 1);
408
}
409
src/plugin_tc.c
+3
-3
@@ -241,7 +241,7 @@ static void tc_device_commit(struct tc_device *d)
241
}
242
243
char var_name[CONFIG_MAX_NAME + 1];
244
- snprintf(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
244
+ snprintfz(var_name, CONFIG_MAX_NAME, "qos for %s", d->id);
245
if(config_get_boolean("plugin:tc", var_name, enable_new_interfaces)) {
246
RRDSET *st = rrdset_find_bytype(RRD_TYPE_TC, d->id);
247
if(!st) {
@@ -535,7 +535,7 @@ void *tc_main(void *ptr)
535
struct tc_device *device = NULL;
536
struct tc_class *class = NULL;
537
538
- snprintf(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", PLUGINS_DIR "/tc-qos-helper.sh"), rrd_update_every);
538
+ snprintfz(buffer, TC_LINE_MAX, "exec %s %d", config_get("plugin:tc", "script to run to get tc values", PLUGINS_DIR "/tc-qos-helper.sh"), rrd_update_every);
539
debug(D_TC_LOOP, "executing '%s'", buffer);
540
// fp = popen(buffer, "r");
541
fp = mypopen(buffer, &tc_child_pid);
@@ -590,7 +590,7 @@ void *tc_main(void *ptr)
590
591
char leafbuf[20 + 1] = "";
592
if(leafid && leafid[strlen(leafid) - 1] == ':') {
593
- strncpy(leafbuf, leafid, 20 - 1);
593
+ strncpyz(leafbuf, leafid, 20 - 1);
594
strcat(leafbuf, "1");
595
leafid = leafbuf;
596
}
src/plugins_d.c
+5
-5
@@ -470,7 +470,7 @@ void *pluginsd_main(void *ptr)
470
}
471
472
char pluginname[CONFIG_MAX_NAME + 1];
473
- snprintf(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name);
473
+ snprintfz(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name);
474
int enabled = config_get_boolean("plugins", pluginname, automatic_run);
475
476
if(unlikely(!enabled)) {
@@ -493,17 +493,17 @@ void *pluginsd_main(void *ptr)
493
cd = calloc(sizeof(struct plugind), 1);
494
if(unlikely(!cd)) fatal("Cannot allocate memory for plugin.");
495
496
- snprintf(cd->id, CONFIG_MAX_NAME, "plugin:%s", pluginname);
496
+ snprintfz(cd->id, CONFIG_MAX_NAME, "plugin:%s", pluginname);
497
498
- strncpy(cd->filename, file->d_name, FILENAME_MAX);
499
- snprintf(cd->fullfilename, FILENAME_MAX, "%s/%s", dir_name, cd->filename);
498
+ strncpyz(cd->filename, file->d_name, FILENAME_MAX);
499
+ snprintfz(cd->fullfilename, FILENAME_MAX, "%s/%s", dir_name, cd->filename);
500
501
cd->enabled = enabled;
502
cd->update_every = (int) config_get_number(cd->id, "update every", rrd_update_every);
503
cd->started_t = time(NULL);
504
505
char *def = "";
506
- snprintf(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", def));
506
+ snprintfz(cd->cmd, PLUGINSD_CMD_MAX, "exec %s %d %s", cd->fullfilename, cd->update_every, config_get(cd->id, "command options", def));
507
508
// link it
509
if(likely(pluginsd_root)) cd->next = pluginsd_root;
src/proc_diskstats.c
+9
-10
@@ -46,8 +46,8 @@ struct disk *get_disk(unsigned long major, unsigned long minor) {
46
47
if(unlikely(!path_find_block_device_partition[0])) {
48
char filename[FILENAME_MAX + 1];
49
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/dev/block/%lu:%lu/partition");
50
- snprintf(path_find_block_device_partition, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get block device partition", filename));
49
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/dev/block/%lu:%lu/partition");
50
+ snprintfz(path_find_block_device_partition, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get block device partition", filename));
51
}
52
53
// not found
@@ -72,7 +72,7 @@ struct disk *get_disk(unsigned long major, unsigned long minor) {
72
// find if it is a partition
73
// by reading /sys/dev/block/MAJOR:MINOR/partition
74
char buffer[FILENAME_MAX + 1];
75
- snprintf(buffer, FILENAME_MAX, path_find_block_device_partition, major, minor);
75
+ snprintfz(buffer, FILENAME_MAX, path_find_block_device_partition, major, minor);
76
77
int fd = open(buffer, O_RDONLY, 0666);
78
if(likely(fd != -1)) {
@@ -128,15 +128,15 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
128
129
if(!ff) {
130
char filename[FILENAME_MAX + 1];
131
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/diskstats");
131
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/diskstats");
132
ff = procfile_open(config_get("plugin:proc:/proc/diskstats", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
133
}
134
if(!ff) return 1;
135
136
if(!path_to_get_hw_sector_size[0]) {
137
char filename[FILENAME_MAX + 1];
138
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/block/%s/queue/hw_sector_size");
139
- snprintf(path_to_get_hw_sector_size, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", filename));
138
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/block/%s/queue/hw_sector_size");
139
+ snprintfz(path_to_get_hw_sector_size, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", filename));
140
}
141
142
ff = procfile_readall(ff);
@@ -345,7 +345,7 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
345
// check which charts are enabled for this disk
346
{
347
char var_name[4096 + 1];
348
- snprintf(var_name, 4096, "plugin:proc:/proc/diskstats:%s", disk);
348
+ snprintfz(var_name, 4096, "plugin:proc:/proc/diskstats:%s", disk);
349
def_enabled = config_get_boolean_ondemand(var_name, "enabled", def_enabled);
350
if(def_enabled == CONFIG_ONDEMAND_NO) continue;
351
if(def_enabled == CONFIG_ONDEMAND_ONDEMAND && !reads && !writes) continue;
@@ -383,13 +383,12 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
383
char tf[FILENAME_MAX + 1], *t;
384
char ssfilename[FILENAME_MAX + 1];
385
386
- strncpy(tf, disk, FILENAME_MAX);
387
- tf[FILENAME_MAX] = '\0';
386
+ strncpyz(tf, disk, FILENAME_MAX);
387
388
// replace all / with !
389
while((t = strchr(tf, '/'))) *t = '!';
390
392
- snprintf(ssfilename, FILENAME_MAX, path_to_get_hw_sector_size, tf);
391
+ snprintfz(ssfilename, FILENAME_MAX, path_to_get_hw_sector_size, tf);
392
FILE *fpss = fopen(ssfilename, "r");
393
if(fpss) {
394
char ssbuffer[1025];
src/proc_loadavg.c
+1
-1
@@ -20,7 +20,7 @@ int do_proc_loadavg(int update_every, unsigned long long dt) {
20
21
if(!ff) {
22
char filename[FILENAME_MAX + 1];
23
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/loadavg");
23
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/loadavg");
24
ff = procfile_open(config_get("plugin:proc:/proc/loadavg", "filename to monitor", filename), " \t,:|/", PROCFILE_FLAG_DEFAULT);
25
}
26
if(!ff) return 1;
src/proc_meminfo.c
+1
-1
@@ -32,7 +32,7 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
32
33
if(!ff) {
34
char filename[FILENAME_MAX + 1];
35
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/meminfo");
35
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/meminfo");
36
ff = procfile_open(config_get("plugin:proc:/proc/meminfo", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
37
}
38
if(!ff) return 1;
src/proc_net_dev.c
+2
-2
@@ -20,7 +20,7 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
20
21
if(!ff) {
22
char filename[FILENAME_MAX + 1];
23
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/dev");
23
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/dev");
24
ff = procfile_open(config_get("plugin:proc:/proc/net/dev", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
25
}
26
if(!ff) return 1;
@@ -86,7 +86,7 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
86
// check if the user wants it
87
{
88
char var_name[512 + 1];
89
- snprintf(var_name, 512, "plugin:proc:/proc/net/dev:%s", iface);
89
+ snprintfz(var_name, 512, "plugin:proc:/proc/net/dev:%s", iface);
90
default_enable = config_get_boolean_ondemand(var_name, "enabled", default_enable);
91
if(default_enable == CONFIG_ONDEMAND_NO) continue;
92
if(default_enable == CONFIG_ONDEMAND_ONDEMAND && !rbytes && !tbytes) continue;
src/proc_net_ip_vs_stats.c
+1
-1
@@ -25,7 +25,7 @@ int do_proc_net_ip_vs_stats(int update_every, unsigned long long dt) {
25
26
if(!ff) {
27
char filename[FILENAME_MAX + 1];
28
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/ip_vs_stats");
28
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/ip_vs_stats");
29
ff = procfile_open(config_get("plugin:proc:/proc/net/ip_vs_stats", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
30
}
31
if(!ff) return 1;
src/proc_net_netstat.c
+1
-1
@@ -27,7 +27,7 @@ int do_proc_net_netstat(int update_every, unsigned long long dt) {
27
28
if(!ff) {
29
char filename[FILENAME_MAX + 1];
30
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
30
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
31
ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
32
}
33
if(!ff) return 1;
src/proc_net_rpc_nfsd.c
+1
-1
@@ -142,7 +142,7 @@ int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
142
143
if(!ff) {
144
char filename[FILENAME_MAX + 1];
145
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/rpc/nfsd");
145
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/rpc/nfsd");
146
ff = procfile_open(config_get("plugin:proc:/proc/net/rpc/nfsd", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
147
}
148
if(!ff) return 1;
src/proc_net_snmp.c
+1
-1
@@ -36,7 +36,7 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
36
37
if(!ff) {
38
char filename[FILENAME_MAX + 1];
39
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/snmp");
39
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/snmp");
40
ff = procfile_open(config_get("plugin:proc:/proc/net/snmp", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
41
}
42
if(!ff) return 1;
src/proc_net_snmp6.c
+1
-1
@@ -254,7 +254,7 @@ int do_proc_net_snmp6(int update_every, unsigned long long dt) {
254
255
if(!ff) {
256
char filename[FILENAME_MAX + 1];
257
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/snmp6");
257
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/snmp6");
258
ff = procfile_open(config_get("plugin:proc:/proc/net/snmp6", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
259
}
260
if(!ff) return 1;
src/proc_net_stat_conntrack.c
+1
-1
@@ -31,7 +31,7 @@ int do_proc_net_stat_conntrack(int update_every, unsigned long long dt) {
31
32
if(!ff) {
33
char filename[FILENAME_MAX + 1];
34
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/stat/nf_conntrack");
34
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/stat/nf_conntrack");
35
ff = procfile_open(config_get("plugin:proc:/proc/net/stat/nf_conntrack", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
36
}
37
if(!ff) return 1;
src/proc_net_stat_synproxy.c
+1
-1
@@ -28,7 +28,7 @@ int do_proc_net_stat_synproxy(int update_every, unsigned long long dt) {
28
29
if(!ff) {
30
char filename[FILENAME_MAX + 1];
31
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/stat/synproxy");
31
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/stat/synproxy");
32
ff = procfile_open(config_get("plugin:proc:/proc/net/stat/synproxy", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
33
}
34
if(!ff) return 1;
src/proc_self_mountinfo.c
+2
-2
@@ -106,10 +106,10 @@ struct mountinfo *mountinfo_read() {
106
procfile *ff = NULL;
107
108
char filename[FILENAME_MAX + 1];
109
- snprintf(filename, FILENAME_MAX, "%s/proc/self/mountinfo", global_host_prefix);
109
+ snprintfz(filename, FILENAME_MAX, "%s/proc/self/mountinfo", global_host_prefix);
110
ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
111
if(!ff) {
112
- snprintf(filename, FILENAME_MAX, "%s/proc/1/mountinfo", global_host_prefix);
112
+ snprintfz(filename, FILENAME_MAX, "%s/proc/1/mountinfo", global_host_prefix);
113
ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
114
if(!ff) return NULL;
115
}
src/proc_stat.c
+1
-1
@@ -30,7 +30,7 @@ int do_proc_stat(int update_every, unsigned long long dt) {
30
31
if(!ff) {
32
char filename[FILENAME_MAX + 1];
33
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/stat");
33
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/stat");
34
ff = procfile_open(config_get("plugin:proc:/proc/stat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
35
}
36
if(!ff) return 1;
src/proc_sys_kernel_random_entropy_avail.c
+1
-1
@@ -17,7 +17,7 @@ int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long
17
18
if(!ff) {
19
char filename[FILENAME_MAX + 1];
20
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/sys/kernel/random/entropy_avail");
20
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/sys/kernel/random/entropy_avail");
21
ff = procfile_open(config_get("plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", filename), "", PROCFILE_FLAG_DEFAULT);
22
}
23
if(!ff) return 1;
src/proc_vmstat.c
+1
-1
@@ -214,7 +214,7 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
214
215
if(!ff) {
216
char filename[FILENAME_MAX + 1];
217
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/vmstat");
217
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/vmstat");
218
ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
219
}
220
if(!ff) return 1;
src/procfile.c
+2
-4
@@ -445,8 +445,7 @@ procfile *procfile_open(const char *filename, const char *separators, uint32_t f
445
return NULL;
446
}
447
448
- strncpy(ff->filename, filename, FILENAME_MAX);
449
- ff->filename[FILENAME_MAX] = '\0';
448
+ strncpyz(ff->filename, filename, FILENAME_MAX);
449
450
ff->fd = fd;
451
ff->size = size;
@@ -479,8 +478,7 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa
478
return NULL;
479
}
480
482
- strncpy(ff->filename, filename, FILENAME_MAX);
483
- ff->filename[FILENAME_MAX] = '\0';
481
+ strncpyz(ff->filename, filename, FILENAME_MAX);
482
483
ff->flags = flags;
484
src/rrd.c
+16
-20
@@ -67,8 +67,7 @@ avl_tree rrdset_root_index = {
67
68
static RRDSET *rrdset_index_find(const char *id, uint32_t hash) {
69
RRDSET *result = NULL, tmp;
70
- strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
71
- tmp.id[RRD_ID_LENGTH_MAX] = '\0';
70
+ strncpyz(tmp.id, id, RRD_ID_LENGTH_MAX);
71
tmp.hash = (hash)?hash:simple_hash(tmp.id);
72
73
avl_search(&(rrdset_root_index), (avl *)&tmp, rrdset_iterator, (avl **)&result);
@@ -149,8 +148,7 @@ static int rrddim_compare(void* a, void* b) {
148
149
static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
150
RRDDIM *result = NULL, tmp;
152
- strncpy(tmp.id, id, RRD_ID_LENGTH_MAX);
153
- tmp.id[RRD_ID_LENGTH_MAX] = '\0';
151
+ strncpyz(tmp.id, id, RRD_ID_LENGTH_MAX);
152
tmp.hash = (hash)?hash:simple_hash(tmp.id);
153
154
avl_search(&(st->dimensions_index), (avl *)&tmp, rrddim_iterator, (avl **)&result);
@@ -281,7 +279,7 @@ void rrdset_set_name(RRDSET *st, const char *name)
279
char b[CONFIG_MAX_VALUE + 1];
280
char n[RRD_ID_LENGTH_MAX + 1];
281
284
- snprintf(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
282
+ snprintfz(n, RRD_ID_LENGTH_MAX, "%s.%s", st->type, name);
283
rrdset_strncpy_name(b, n, CONFIG_MAX_VALUE);
284
st->name = config_get(st->id, "name", b);
285
st->hash_name = simple_hash(st->name);
@@ -303,7 +301,7 @@ char *rrdset_cache_dir(const char *id)
301
char n[FILENAME_MAX + 1];
302
rrdset_strncpy_name(b, id, FILENAME_MAX);
303
306
- snprintf(n, FILENAME_MAX, "%s/%s", cache_dir, b);
304
+ snprintfz(n, FILENAME_MAX, "%s/%s", cache_dir, b);
305
ret = config_get(id, "cache directory", n);
306
307
if(rrd_memory_mode == RRD_MEMORY_MODE_MAP || rrd_memory_mode == RRD_MEMORY_MODE_SAVE) {
@@ -355,7 +353,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
353
char fullfilename[FILENAME_MAX + 1];
354
RRDSET *st = NULL;
355
358
- snprintf(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
356
+ snprintfz(fullid, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
357
358
st = rrdset_find(fullid);
359
if(st) {
@@ -375,7 +373,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
373
374
debug(D_RRD_CALLS, "Creating RRD_STATS for '%s.%s'.", type, id);
375
378
- snprintf(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
376
+ snprintfz(fullfilename, FILENAME_MAX, "%s/main.db", cache_dir);
377
if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) st = (RRDSET *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 0);
378
if(st) {
379
if(strcmp(st->magic, RRDSET_MAGIC) != 0) {
@@ -467,7 +465,7 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
465
466
{
467
char varvalue[CONFIG_MAX_VALUE + 1];
470
- snprintf(varvalue, CONFIG_MAX_VALUE, "%s (%s)", title?title:"", st->name);
468
+ snprintfz(varvalue, CONFIG_MAX_VALUE, "%s (%s)", title?title:"", st->name);
469
st->title = config_get(st->id, "title", varvalue);
470
}
471
@@ -493,7 +491,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
491
debug(D_RRD_CALLS, "Adding dimension '%s/%s'.", st->id, id);
492
493
rrdset_strncpy_name(filename, id, FILENAME_MAX);
496
- snprintf(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
494
+ snprintfz(fullfilename, FILENAME_MAX, "%s/%s.db", st->cache_dir, filename);
495
if(rrd_memory_mode != RRD_MEMORY_MODE_RAM) rd = (RRDDIM *)mymmap(fullfilename, size, ((rrd_memory_mode == RRD_MEMORY_MODE_MAP)?MAP_SHARED:MAP_PRIVATE), 1);
496
if(rd) {
497
struct timeval now;
@@ -565,19 +563,19 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
563
564
strcpy(rd->magic, RRDDIMENSION_MAGIC);
565
strcpy(rd->cache_filename, fullfilename);
568
- strncpy(rd->id, id, RRD_ID_LENGTH_MAX);
566
+ strncpyz(rd->id, id, RRD_ID_LENGTH_MAX);
567
rd->hash = simple_hash(rd->id);
568
571
- snprintf(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
569
+ snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
570
rd->name = config_get(st->id, varname, (name && *name)?name:rd->id);
571
574
- snprintf(varname, CONFIG_MAX_NAME, "dim %s algorithm", rd->id);
572
+ snprintfz(varname, CONFIG_MAX_NAME, "dim %s algorithm", rd->id);
573
rd->algorithm = rrddim_algorithm_id(config_get(st->id, varname, rrddim_algorithm_name(algorithm)));
574
577
- snprintf(varname, CONFIG_MAX_NAME, "dim %s multiplier", rd->id);
575
+ snprintfz(varname, CONFIG_MAX_NAME, "dim %s multiplier", rd->id);
576
rd->multiplier = config_get_number(st->id, varname, multiplier);
577
580
- snprintf(varname, CONFIG_MAX_NAME, "dim %s divisor", rd->id);
578
+ snprintfz(varname, CONFIG_MAX_NAME, "dim %s divisor", rd->id);
579
rd->divisor = config_get_number(st->id, varname, divisor);
580
if(!rd->divisor) rd->divisor = 1;
581
@@ -608,7 +606,7 @@ void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name)
606
debug(D_RRD_CALLS, "rrddim_set_name() %s.%s", st->name, rd->name);
607
608
char varname[CONFIG_MAX_NAME + 1];
611
- snprintf(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
609
+ snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id);
610
config_set_default(st->id, varname, name);
611
}
612
@@ -728,12 +726,10 @@ RRDSET *rrdset_find_bytype(const char *type, const char *id)
726
727
char buf[RRD_ID_LENGTH_MAX + 1];
728
731
- strncpy(buf, type, RRD_ID_LENGTH_MAX - 1);
732
- buf[RRD_ID_LENGTH_MAX - 1] = '\0';
729
+ strncpyz(buf, type, RRD_ID_LENGTH_MAX - 1);
730
strcat(buf, ".");
731
int len = (int) strlen(buf);
735
- strncpy(&buf[len], id, (size_t) (RRD_ID_LENGTH_MAX - len));
736
- buf[RRD_ID_LENGTH_MAX] = '\0';
732
+ strncpyz(&buf[len], id, (size_t) (RRD_ID_LENGTH_MAX - len));
733
734
return(rrdset_find(buf));
735
}
src/rrd2json.c
+27
-27
@@ -682,18 +682,18 @@ static void rrdr2json(RRDR *r, BUFFER *wb, uint32_t options, int datatable)
682
sq[0] = '"';
683
}
684
row_annotations = 1;
685
- snprintf(pre_date, 100, " {%sc%s:[{%sv%s:%s", kq, kq, kq, kq, sq);
686
- snprintf(post_date, 100, "%s}", sq);
687
- snprintf(pre_label, 100, ",\n {%sid%s:%s%s,%slabel%s:%s", kq, kq, sq, sq, kq, kq, sq);
688
- snprintf(post_label, 100, "%s,%spattern%s:%s%s,%stype%s:%snumber%s}", sq, kq, kq, sq, sq, kq, kq, sq, sq);
689
- snprintf(pre_value, 100, ",{%sv%s:", kq, kq);
690
- snprintf(post_value, 100, "}");
691
- snprintf(post_line, 100, "]}");
692
- snprintf(data_begin, 100, "\n ],\n %srows%s:\n [\n", kq, kq);
693
- snprintf(finish, 100, "\n ]\n}");
694
-
695
- snprintf(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
696
- snprintf(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
685
+ snprintfz(pre_date, 100, " {%sc%s:[{%sv%s:%s", kq, kq, kq, kq, sq);
686
+ snprintfz(post_date, 100, "%s}", sq);
687
+ snprintfz(pre_label, 100, ",\n {%sid%s:%s%s,%slabel%s:%s", kq, kq, sq, sq, kq, kq, sq);
688
+ snprintfz(post_label, 100, "%s,%spattern%s:%s%s,%stype%s:%snumber%s}", sq, kq, kq, sq, sq, kq, kq, sq, sq);
689
+ snprintfz(pre_value, 100, ",{%sv%s:", kq, kq);
690
+ strcpy(post_value, "}");
691
+ strcpy(post_line, "]}");
692
+ snprintfz(data_begin, 100, "\n ],\n %srows%s:\n [\n", kq, kq);
693
+ strcpy(finish, "\n ]\n}");
694
+
695
+ snprintfz(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
696
+ snprintfz(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
697
698
buffer_sprintf(wb, "{\n %scols%s:\n [\n", kq, kq, kq, kq);
699
buffer_sprintf(wb, " {%sid%s:%s%s,%slabel%s:%stime%s,%spattern%s:%s%s,%stype%s:%sdatetime%s},\n", kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq, kq, kq, sq, sq);
@@ -717,18 +717,18 @@ static void rrdr2json(RRDR *r, BUFFER *wb, uint32_t options, int datatable)
717
dates_with_new = 1;
718
}
719
if( options & RRDR_OPTION_OBJECTSROWS )
720
- snprintf(pre_date, 100, " { ");
720
+ strcpy(pre_date, " { ");
721
else
722
- snprintf(pre_date, 100, " [ ");
723
- snprintf(pre_label, 100, ", \"");
724
- snprintf(post_label, 100, "\"");
725
- snprintf(pre_value, 100, ", ");
722
+ strcpy(pre_date, " [ ");
723
+ strcpy(pre_label, ", \"");
724
+ strcpy(post_label, "\"");
725
+ strcpy(pre_value, ", ");
726
if( options & RRDR_OPTION_OBJECTSROWS )
727
- snprintf(post_line, 100, "}");
727
+ strcpy(post_line, "}");
728
else
729
- snprintf(post_line, 100, "]");
730
- snprintf(data_begin, 100, "],\n %sdata%s:\n [\n", kq, kq);
731
- snprintf(finish, 100, "\n ]\n}");
729
+ strcpy(post_line, "]");
730
+ snprintfz(data_begin, 100, "],\n %sdata%s:\n [\n", kq, kq);
731
+ strcpy(finish, "\n ]\n}");
732
733
buffer_sprintf(wb, "{\n %slabels%s: [", kq, kq);
734
buffer_sprintf(wb, "%stime%s", sq, sq);
@@ -1743,12 +1743,12 @@ time_t rrd_stats_json(int type, RRDSET *st, BUFFER *wb, long points, long group,
1743
// -------------------------------------------------------------------------
1744
// prepare various strings, to speed up the loop
1745
1746
- char overflow_annotation[201]; snprintf(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
1747
- char normal_annotation[201]; snprintf(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
1748
- char pre_date[51]; snprintf(pre_date, 50, " {%sc%s:[{%sv%s:%s", kq, kq, kq, kq, sq);
1749
- char post_date[21]; snprintf(post_date, 20, "%s}", sq);
1750
- char pre_value[21]; snprintf(pre_value, 20, ",{%sv%s:", kq, kq);
1751
- char post_value[21]; snprintf(post_value, 20, "}");
1746
+ char overflow_annotation[201]; snprintfz(overflow_annotation, 200, ",{%sv%s:%sRESET OR OVERFLOW%s},{%sv%s:%sThe counters have been wrapped.%s}", kq, kq, sq, sq, kq, kq, sq, sq);
1747
+ char normal_annotation[201]; snprintfz(normal_annotation, 200, ",{%sv%s:null},{%sv%s:null}", kq, kq, kq, kq);
1748
+ char pre_date[51]; snprintfz(pre_date, 50, " {%sc%s:[{%sv%s:%s", kq, kq, kq, kq, sq);
1749
+ char post_date[21]; snprintfz(post_date, 20, "%s}", sq);
1750
+ char pre_value[21]; snprintfz(pre_value, 20, ",{%sv%s:", kq, kq);
1751
+ char post_value[21]; strcpy(post_value, "}");
1752
1753
1754
// -------------------------------------------------------------------------
src/storage_number.c
+3
-3
@@ -129,7 +129,7 @@ static char *print_calculated_number_lu_r(char *str, unsigned long uvalue) {
129
char *wstr = str;
130
131
// print each digit
132
- do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
132
+ do *wstr++ = (char)('0' + (uvalue % 10)); while(uvalue /= 10);
133
return wstr;
134
}
135
@@ -137,7 +137,7 @@ static char *print_calculated_number_llu_r(char *str, unsigned long long uvalue)
137
char *wstr = str;
138
139
// print each digit
140
- do *wstr++ = (char)(48 + (uvalue % 10)); while((uvalue /= 10) && uvalue > (unsigned long long)0xffffffff);
140
+ do *wstr++ = (char)('0' + (uvalue % 10)); while((uvalue /= 10) && uvalue > (unsigned long long)0xffffffff);
141
if(uvalue) return print_calculated_number_lu_r(wstr, uvalue);
142
return wstr;
143
}
@@ -164,7 +164,7 @@ int print_calculated_number(char *str, calculated_number value)
164
else
165
wstr = print_calculated_number_lu_r(str, uvalue);
166
#else
167
- do *wstr++ = (char)(48 + (uvalue % 10)); while(uvalue /= 10);
167
+ do *wstr++ = (char)('0' + (uvalue % 10)); while(uvalue /= 10);
168
#endif
169
170
// make sure we have 6 bytes at least
src/sys_fs_cgroup.c
+31
-31
@@ -50,21 +50,21 @@ void read_cgroup_plugin_configuration() {
50
if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "cpuacct");
51
if(!mi) s = "/sys/fs/cgroup/cpuacct";
52
else s = mi->mount_point;
53
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
53
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
54
cgroup_cpuacct_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/cpuacct", filename);
55
56
mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "blkio");
57
if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "blkio");
58
if(!mi) s = "/sys/fs/cgroup/blkio";
59
else s = mi->mount_point;
60
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
60
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
61
cgroup_blkio_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/blkio", filename);
62
63
mi = mountinfo_find_by_filesystem_mount_source(root, "cgroup", "memory");
64
if(!mi) mi = mountinfo_find_by_filesystem_super_option(root, "cgroup", "memory");
65
if(!mi) s = "/sys/fs/cgroup/memory";
66
else s = mi->mount_point;
67
- snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
67
+ snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, s);
68
cgroup_memory_base = config_get("plugin:cgroups", "path to /sys/fs/cgroup/memory", filename);
69
70
cgroup_root_max = config_get_number("plugin:cgroups", "max cgroups to allow", cgroup_root_max);
@@ -589,7 +589,7 @@ void cgroup_get_chart_id(struct cgroup *cg) {
589
pid_t cgroup_pid;
590
char buffer[CGROUP_CHARTID_LINE_MAX + 1];
591
592
- snprintf(buffer, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'",
592
+ snprintfz(buffer, CGROUP_CHARTID_LINE_MAX, "exec %s '%s'",
593
config_get("plugin:cgroups", "script to get cgroup names", PLUGINS_DIR "/cgroup-name.sh"), cg->chart_id);
594
595
debug(D_CGROUP, "executing command '%s' for cgroup '%s'", buffer, cg->id);
@@ -710,7 +710,7 @@ struct cgroup *cgroup_add(const char *id) {
710
cgroup_get_chart_id(cg);
711
712
char option[FILENAME_MAX + 1];
713
- snprintf(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
713
+ snprintfz(option, FILENAME_MAX, "enable cgroup %s", cg->chart_title);
714
cg->enabled = config_get_boolean("plugin:cgroups", option, def);
715
716
debug(D_CGROUP, "Added cgroup '%s' with chart id '%s' and title '%s' as %s (default was %s)", cg->id, cg->chart_id, cg->chart_title, (cg->enabled)?"enabled":"disabled", (def)?"enabled":"disabled");
@@ -818,7 +818,7 @@ void find_dir_in_subdirs(const char *base, const char *this, void (*callback)(co
818
// so that the config will not have settings
819
// for leaf directories
820
char option[FILENAME_MAX + 1];
821
- snprintf(option, FILENAME_MAX, "search for cgroups under %s", r);
821
+ snprintfz(option, FILENAME_MAX, "search for cgroups under %s", r);
822
option[FILENAME_MAX] = '\0';
823
enabled = config_get_boolean("plugin:cgroups", option, 1);
824
}
@@ -904,48 +904,48 @@ void find_all_cgroups() {
904
// and update the filenames they read
905
char filename[FILENAME_MAX + 1];
906
if(cgroup_enable_cpuacct_stat && !cg->cpuacct_stat.filename) {
907
- snprintf(filename, FILENAME_MAX, "%s%s/cpuacct.stat", cgroup_cpuacct_base, cg->id);
907
+ snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.stat", cgroup_cpuacct_base, cg->id);
908
cg->cpuacct_stat.filename = strdup(filename);
909
debug(D_CGROUP, "cpuacct.stat filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_stat.filename);
910
}
911
if(cgroup_enable_cpuacct_usage && !cg->cpuacct_usage.filename) {
912
- snprintf(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
912
+ snprintfz(filename, FILENAME_MAX, "%s%s/cpuacct.usage_percpu", cgroup_cpuacct_base, cg->id);
913
cg->cpuacct_usage.filename = strdup(filename);
914
debug(D_CGROUP, "cpuacct.usage_percpu filename for cgroup '%s': '%s'", cg->id, cg->cpuacct_usage.filename);
915
}
916
if(cgroup_enable_memory && !cg->memory.filename) {
917
- snprintf(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
917
+ snprintfz(filename, FILENAME_MAX, "%s%s/memory.stat", cgroup_memory_base, cg->id);
918
cg->memory.filename = strdup(filename);
919
debug(D_CGROUP, "memory.stat filename for cgroup '%s': '%s'", cg->id, cg->memory.filename);
920
}
921
if(cgroup_enable_blkio) {
922
if(!cg->io_service_bytes.filename) {
923
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
923
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_service_bytes", cgroup_blkio_base, cg->id);
924
cg->io_service_bytes.filename = strdup(filename);
925
debug(D_CGROUP, "io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->io_service_bytes.filename);
926
}
927
if(!cg->io_serviced.filename) {
928
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
928
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_serviced", cgroup_blkio_base, cg->id);
929
cg->io_serviced.filename = strdup(filename);
930
debug(D_CGROUP, "io_serviced filename for cgroup '%s': '%s'", cg->id, cg->io_serviced.filename);
931
}
932
if(!cg->throttle_io_service_bytes.filename) {
933
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
933
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_service_bytes", cgroup_blkio_base, cg->id);
934
cg->throttle_io_service_bytes.filename = strdup(filename);
935
debug(D_CGROUP, "throttle_io_service_bytes filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_service_bytes.filename);
936
}
937
if(!cg->throttle_io_serviced.filename) {
938
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
938
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.throttle.io_serviced", cgroup_blkio_base, cg->id);
939
cg->throttle_io_serviced.filename = strdup(filename);
940
debug(D_CGROUP, "throttle_io_serviced filename for cgroup '%s': '%s'", cg->id, cg->throttle_io_serviced.filename);
941
}
942
if(!cg->io_merged.filename) {
943
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
943
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_merged", cgroup_blkio_base, cg->id);
944
cg->io_merged.filename = strdup(filename);
945
debug(D_CGROUP, "io_merged filename for cgroup '%s': '%s'", cg->id, cg->io_merged.filename);
946
}
947
if(!cg->io_queued.filename) {
948
- snprintf(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
948
+ snprintfz(filename, FILENAME_MAX, "%s%s/blkio.io_queued", cgroup_blkio_base, cg->id);
949
cg->io_queued.filename = strdup(filename);
950
debug(D_CGROUP, "io_queued filename for cgroup '%s': '%s'", cg->id, cg->io_queued.filename);
951
}
@@ -977,16 +977,16 @@ void update_cgroup_charts(int update_every) {
977
if(cg->id[0] == '\0')
978
strcpy(type, "cgroup_root");
979
else if(cg->id[0] == '/')
980
- snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
980
+ snprintfz(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
981
else
982
- snprintf(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
982
+ snprintfz(type, RRD_ID_LENGTH_MAX, "cgroup_%s", cg->chart_id);
983
984
netdata_fix_chart_id(type);
985
986
if(cg->cpuacct_stat.updated) {
987
st = rrdset_find_bytype(type, "cpu");
988
if(!st) {
989
- snprintf(title, CHART_TITLE_MAX, "CPU Usage for cgroup %s", cg->chart_title);
989
+ snprintfz(title, CHART_TITLE_MAX, "CPU Usage for cgroup %s", cg->chart_title);
990
st = rrdset_create(type, "cpu", NULL, "cpu", "cgroup.cpu", title, "%", 40000, update_every, RRDSET_TYPE_STACKED);
991
992
rrddim_add(st, "user", NULL, 100, hz, RRDDIM_INCREMENTAL);
@@ -1005,18 +1005,18 @@ void update_cgroup_charts(int update_every) {
1005
1006
st = rrdset_find_bytype(type, "cpu_per_core");
1007
if(!st) {
1008
- snprintf(title, CHART_TITLE_MAX, "CPU Usage Per Core for cgroup %s", cg->chart_title);
1008
+ snprintfz(title, CHART_TITLE_MAX, "CPU Usage Per Core for cgroup %s", cg->chart_title);
1009
st = rrdset_create(type, "cpu_per_core", NULL, "cpu", "cgroup.cpu_per_core", title, "%", 40100, update_every, RRDSET_TYPE_STACKED);
1010
1011
for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
1012
- snprintf(id, CHART_TITLE_MAX, "cpu%d", i);
1012
+ snprintfz(id, CHART_TITLE_MAX, "cpu%d", i);
1013
rrddim_add(st, id, NULL, 100, 1000000, RRDDIM_INCREMENTAL);
1014
}
1015
}
1016
else rrdset_next(st);
1017
1018
for(i = 0; i < cg->cpuacct_usage.cpus ;i++) {
1019
- snprintf(id, CHART_TITLE_MAX, "cpu%d", i);
1019
+ snprintfz(id, CHART_TITLE_MAX, "cpu%d", i);
1020
rrddim_set(st, id, cg->cpuacct_usage.cpu_percpu[i]);
1021
}
1022
rrdset_done(st);
@@ -1026,7 +1026,7 @@ void update_cgroup_charts(int update_every) {
1026
if(cg->memory.cache + cg->memory.rss + cg->memory.rss_huge + cg->memory.mapped_file > 0) {
1027
st = rrdset_find_bytype(type, "mem");
1028
if(!st) {
1029
- snprintf(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_title);
1029
+ snprintfz(title, CHART_TITLE_MAX, "Memory Usage for cgroup %s", cg->chart_title);
1030
st = rrdset_create(type, "mem", NULL, "mem", "cgroup.mem", title, "MB", 40200, update_every,
1031
RRDSET_TYPE_STACKED);
1032
@@ -1050,7 +1050,7 @@ void update_cgroup_charts(int update_every) {
1050
1051
st = rrdset_find_bytype(type, "writeback");
1052
if(!st) {
1053
- snprintf(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_title);
1053
+ snprintfz(title, CHART_TITLE_MAX, "Writeback Memory for cgroup %s", cg->chart_title);
1054
st = rrdset_create(type, "writeback", NULL, "mem", "cgroup.writeback", title, "MB", 40300,
1055
update_every, RRDSET_TYPE_AREA);
1056
@@ -1068,7 +1068,7 @@ void update_cgroup_charts(int update_every) {
1068
if(cg->memory.pgpgin + cg->memory.pgpgout > 0) {
1069
st = rrdset_find_bytype(type, "mem_activity");
1070
if(!st) {
1071
- snprintf(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
1071
+ snprintfz(title, CHART_TITLE_MAX, "Memory Activity for cgroup %s", cg->chart_title);
1072
st = rrdset_create(type, "mem_activity", NULL, "mem", "cgroup.mem_activity", title, "MB/s",
1073
40400, update_every, RRDSET_TYPE_LINE);
1074
@@ -1085,7 +1085,7 @@ void update_cgroup_charts(int update_every) {
1085
if(cg->memory.pgfault + cg->memory.pgmajfault > 0) {
1086
st = rrdset_find_bytype(type, "pgfaults");
1087
if(!st) {
1088
- snprintf(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
1088
+ snprintfz(title, CHART_TITLE_MAX, "Memory Page Faults for cgroup %s", cg->chart_title);
1089
st = rrdset_create(type, "pgfaults", NULL, "mem", "cgroup.pgfaults", title, "MB/s", 40500,
1090
update_every, RRDSET_TYPE_LINE);
1091
@@ -1103,7 +1103,7 @@ void update_cgroup_charts(int update_every) {
1103
if(cg->io_service_bytes.updated && cg->io_service_bytes.Read + cg->io_service_bytes.Write > 0) {
1104
st = rrdset_find_bytype(type, "io");
1105
if(!st) {
1106
- snprintf(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1106
+ snprintfz(title, CHART_TITLE_MAX, "I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1107
st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1108
update_every, RRDSET_TYPE_LINE);
1109
@@ -1120,7 +1120,7 @@ void update_cgroup_charts(int update_every) {
1120
if(cg->io_serviced.updated && cg->io_serviced.Read + cg->io_serviced.Write > 0) {
1121
st = rrdset_find_bytype(type, "serviced_ops");
1122
if(!st) {
1123
- snprintf(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1123
+ snprintfz(title, CHART_TITLE_MAX, "Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1124
st = rrdset_create(type, "serviced_ops", NULL, "disk", "cgroup.serviced_ops", title, "operations/s", 41200,
1125
update_every, RRDSET_TYPE_LINE);
1126
@@ -1137,7 +1137,7 @@ void update_cgroup_charts(int update_every) {
1137
if(cg->throttle_io_service_bytes.updated && cg->throttle_io_service_bytes.Read + cg->throttle_io_service_bytes.Write > 0) {
1138
st = rrdset_find_bytype(type, "io");
1139
if(!st) {
1140
- snprintf(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1140
+ snprintfz(title, CHART_TITLE_MAX, "Throttle I/O Bandwidth (all disks) for cgroup %s", cg->chart_title);
1141
st = rrdset_create(type, "io", NULL, "disk", "cgroup.io", title, "KB/s", 41200,
1142
update_every, RRDSET_TYPE_LINE);
1143
@@ -1155,7 +1155,7 @@ void update_cgroup_charts(int update_every) {
1155
if(cg->throttle_io_serviced.updated && cg->throttle_io_serviced.Read + cg->throttle_io_serviced.Write > 0) {
1156
st = rrdset_find_bytype(type, "throttle_serviced_ops");
1157
if(!st) {
1158
- snprintf(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1158
+ snprintfz(title, CHART_TITLE_MAX, "Throttle Serviced I/O Operations (all disks) for cgroup %s", cg->chart_title);
1159
st = rrdset_create(type, "throttle_serviced_ops", NULL, "disk", "cgroup.throttle_serviced_ops", title, "operations/s", 41200,
1160
update_every, RRDSET_TYPE_LINE);
1161
@@ -1172,7 +1172,7 @@ void update_cgroup_charts(int update_every) {
1172
if(cg->io_queued.updated) {
1173
st = rrdset_find_bytype(type, "queued_ops");
1174
if(!st) {
1175
- snprintf(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
1175
+ snprintfz(title, CHART_TITLE_MAX, "Queued I/O Operations (all disks) for cgroup %s", cg->chart_title);
1176
st = rrdset_create(type, "queued_ops", NULL, "disk", "cgroup.queued_ops", title, "operations", 42000,
1177
update_every, RRDSET_TYPE_LINE);
1178
@@ -1189,7 +1189,7 @@ void update_cgroup_charts(int update_every) {
1189
if(cg->io_merged.updated && cg->io_merged.Read + cg->io_merged.Write > 0) {
1190
st = rrdset_find_bytype(type, "merged_ops");
1191
if(!st) {
1192
- snprintf(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
1192
+ snprintfz(title, CHART_TITLE_MAX, "Merged I/O Operations (all disks) for cgroup %s", cg->chart_title);
1193
st = rrdset_create(type, "merged_ops", NULL, "disk", "cgroup.merged_ops", title, "operations/s", 42100,
1194
update_every, RRDSET_TYPE_LINE);
1195
src/sys_kernel_mm_ksm.c
+10
-10
@@ -41,32 +41,32 @@ int do_sys_kernel_mm_ksm(int update_every, unsigned long long dt) {
41
page_size = sysconf(_SC_PAGESIZE);
42
43
if(!ff_pages_shared) {
44
- snprintf(values[PAGES_SHARED].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_shared");
45
- snprintf(values[PAGES_SHARED].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_shared", values[PAGES_SHARED].filename));
44
+ snprintfz(values[PAGES_SHARED].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_shared");
45
+ snprintfz(values[PAGES_SHARED].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_shared", values[PAGES_SHARED].filename));
46
ff_pages_shared = procfile_open(values[PAGES_SHARED].filename, " \t:", PROCFILE_FLAG_DEFAULT);
47
}
48
49
if(!ff_pages_sharing) {
50
- snprintf(values[PAGES_SHARING].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_sharing");
51
- snprintf(values[PAGES_SHARING].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_sharing", values[PAGES_SHARING].filename));
50
+ snprintfz(values[PAGES_SHARING].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_sharing");
51
+ snprintfz(values[PAGES_SHARING].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_sharing", values[PAGES_SHARING].filename));
52
ff_pages_sharing = procfile_open(values[PAGES_SHARING].filename, " \t:", PROCFILE_FLAG_DEFAULT);
53
}
54
55
if(!ff_pages_unshared) {
56
- snprintf(values[PAGES_UNSHARED].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_unshared");
57
- snprintf(values[PAGES_UNSHARED].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_unshared", values[PAGES_UNSHARED].filename));
56
+ snprintfz(values[PAGES_UNSHARED].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_unshared");
57
+ snprintfz(values[PAGES_UNSHARED].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_unshared", values[PAGES_UNSHARED].filename));
58
ff_pages_unshared = procfile_open(values[PAGES_UNSHARED].filename, " \t:", PROCFILE_FLAG_DEFAULT);
59
}
60
61
if(!ff_pages_volatile) {
62
- snprintf(values[PAGES_VOLATILE].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_volatile");
63
- snprintf(values[PAGES_VOLATILE].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_volatile", values[PAGES_VOLATILE].filename));
62
+ snprintfz(values[PAGES_VOLATILE].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_volatile");
63
+ snprintfz(values[PAGES_VOLATILE].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_volatile", values[PAGES_VOLATILE].filename));
64
ff_pages_volatile = procfile_open(values[PAGES_VOLATILE].filename, " \t:", PROCFILE_FLAG_DEFAULT);
65
}
66
67
if(!ff_pages_to_scan) {
68
- snprintf(values[PAGES_TO_SCAN].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_to_scan");
69
- snprintf(values[PAGES_TO_SCAN].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_to_scan", values[PAGES_TO_SCAN].filename));
68
+ snprintfz(values[PAGES_TO_SCAN].filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/kernel/mm/ksm/pages_to_scan");
69
+ snprintfz(values[PAGES_TO_SCAN].filename, FILENAME_MAX, "%s", config_get("plugin:proc:/sys/kernel/mm/ksm", "/sys/kernel/mm/ksm/pages_to_scan", values[PAGES_TO_SCAN].filename));
70
ff_pages_to_scan = procfile_open(values[PAGES_TO_SCAN].filename, " \t:", PROCFILE_FLAG_DEFAULT);
71
}
72
src/unit_test.c
+3
-3
@@ -128,7 +128,7 @@ void benchmark_storage_number(int loop, int multiplier) {
128
for(i = 0; i < loop ;i++) {
129
n *= multiplier;
130
if(n > STORAGE_NUMBER_POSITIVE_MAX) n = STORAGE_NUMBER_POSITIVE_MIN;
131
- snprintf(buffer, 100, CALCULATED_NUMBER_FORMAT, n);
131
+ snprintfz(buffer, 100, CALCULATED_NUMBER_FORMAT, n);
132
}
133
}
134
@@ -614,7 +614,7 @@ int run_test(struct test *test)
614
rrd_update_every = test->update_every;
615
616
char name[101];
617
- snprintf(name, 100, "unittest-%s", test->name);
617
+ snprintfz(name, 100, "unittest-%s", test->name);
618
619
// create the chart
620
RRDSET *st = rrdset_create("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", 1, 1, RRDSET_TYPE_LINE);
@@ -703,7 +703,7 @@ int unit_test(long delay, long shift)
703
repeat++;
704
705
char name[101];
706
- snprintf(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
706
+ snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift);
707
708
//debug_flags = 0xffffffff;
709
rrd_memory_mode = RRD_MEMORY_MODE_RAM;
src/web_buffer.c
+7
-7
@@ -53,7 +53,7 @@ void buffer_reset(BUFFER *wb)
53
54
const char *buffer_tostring(BUFFER *wb)
55
{
56
- buffer_need_bytes(wb, (size_t)1);
56
+ buffer_need_bytes(wb, 1);
57
wb->buffer[wb->len] = '\0';
58
59
buffer_overflow_check(wb);
@@ -78,7 +78,7 @@ void buffer_strcat(BUFFER *wb, const char *txt)
78
{
79
if(unlikely(!txt || !*txt)) return;
80
81
- buffer_need_bytes(wb, (size_t)(1));
81
+ buffer_need_bytes(wb, 1);
82
83
char *s = &wb->buffer[wb->len], *end = &wb->buffer[wb->size];
84
long len = wb->len;
@@ -114,12 +114,12 @@ void buffer_snprintf(BUFFER *wb, size_t len, const char *fmt, ...)
114
115
va_list args;
116
va_start(args, fmt);
117
- wb->len += vsnprintf(&wb->buffer[wb->len], len+1, fmt, args);
117
+ wb->len += vsnprintfz(&wb->buffer[wb->len], len, fmt, args);
118
va_end(args);
119
120
buffer_overflow_check(wb);
121
122
- // the buffer is \0 terminated by vsnprintf
122
+ // the buffer is \0 terminated by vsnprintfz
123
}
124
125
void buffer_vsprintf(BUFFER *wb, const char *fmt, va_list args)
@@ -130,11 +130,11 @@ void buffer_vsprintf(BUFFER *wb, const char *fmt, va_list args)
130
131
size_t len = wb->size - wb->len;
132
133
- wb->len += vsnprintf(&wb->buffer[wb->len], len, fmt, args);
133
+ wb->len += vsnprintfz(&wb->buffer[wb->len], len, fmt, args);
134
135
buffer_overflow_check(wb);
136
137
- // the buffer is \0 terminated by vsnprintf
137
+ // the buffer is \0 terminated by vsnprintfz
138
}
139
140
void buffer_sprintf(BUFFER *wb, const char *fmt, ...)
@@ -147,7 +147,7 @@ void buffer_sprintf(BUFFER *wb, const char *fmt, ...)
147
148
va_list args;
149
va_start(args, fmt);
150
- wrote = (size_t) vsnprintf(&wb->buffer[wb->len], len, fmt, args);
150
+ wrote = (size_t) vsnprintfz(&wb->buffer[wb->len], len, fmt, args);
151
va_end(args);
152
153
if(unlikely(wrote >= len)) {
src/web_client.c
+8
-12
@@ -72,8 +72,8 @@ struct web_client *web_client_create(int listener)
72
73
if(getnameinfo(sadr, addrlen, w->client_ip, NI_MAXHOST, w->client_port, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
74
error("Cannot getnameinfo() on received client connection.");
75
- strncpy(w->client_ip, "UNKNOWN", NI_MAXHOST);
76
- strncpy(w->client_port, "UNKNOWN", NI_MAXSERV);
75
+ strncpyz(w->client_ip, "UNKNOWN", NI_MAXHOST);
76
+ strncpyz(w->client_port, "UNKNOWN", NI_MAXSERV);
77
}
78
w->client_ip[NI_MAXHOST] = '\0';
79
w->client_port[NI_MAXSERV] = '\0';
@@ -316,7 +316,7 @@ int mysendfile(struct web_client *w, char *filename)
316
317
// access the file
318
char webfilename[FILENAME_MAX + 1];
319
- snprintf(webfilename, FILENAME_MAX, "%s/%s", web_dir, filename);
319
+ snprintfz(webfilename, FILENAME_MAX, "%s/%s", web_dir, filename);
320
321
// check if the file exists
322
struct stat stat;
@@ -341,7 +341,7 @@ int mysendfile(struct web_client *w, char *filename)
341
}
342
343
if((stat.st_mode & S_IFMT) == S_IFDIR) {
344
- snprintf(webfilename, FILENAME_MAX+1, "%s/index.html", filename);
344
+ snprintfz(webfilename, FILENAME_MAX, "%s/index.html", filename);
345
return mysendfile(w, webfilename);
346
}
347
@@ -1101,8 +1101,7 @@ void web_client_process(struct web_client *w) {
1101
w->last_url[0] = '\0';
1102
1103
if(w->mode == WEB_CLIENT_MODE_OPTIONS) {
1104
- strncpy(w->last_url, url, URL_MAX);
1105
- w->last_url[URL_MAX] = '\0';
1104
+ strncpyz(w->last_url, url, URL_MAX);
1105
1106
code = 200;
1107
w->response.data->contenttype = CT_TEXT_PLAIN;
@@ -1115,8 +1114,7 @@ void web_client_process(struct web_client *w) {
1114
web_client_enable_deflate(w);
1115
#endif
1116
1118
- strncpy(w->last_url, url, URL_MAX);
1119
- w->last_url[URL_MAX] = '\0';
1117
+ strncpyz(w->last_url, url, URL_MAX);
1118
1119
tok = mystrsep(&url, "/?");
1120
if(tok && *tok) {
@@ -1249,8 +1247,7 @@ void web_client_process(struct web_client *w) {
1247
else {
1248
char filename[FILENAME_MAX+1];
1249
url = filename;
1252
- strncpy(filename, w->last_url, FILENAME_MAX);
1253
- filename[FILENAME_MAX] = '\0';
1250
+ strncpyz(filename, w->last_url, FILENAME_MAX);
1251
tok = mystrsep(&url, "?");
1252
buffer_flush(w->response.data);
1253
code = mysendfile(w, (tok && *tok)?tok:"/");
@@ -1259,8 +1256,7 @@ void web_client_process(struct web_client *w) {
1256
else {
1257
char filename[FILENAME_MAX+1];
1258
url = filename;
1262
- strncpy(filename, w->last_url, FILENAME_MAX);
1263
- filename[FILENAME_MAX] = '\0';
1259
+ strncpyz(filename, w->last_url, FILENAME_MAX);
1260
tok = mystrsep(&url, "?");
1261
buffer_flush(w->response.data);
1262
code = mysendfile(w, (tok && *tok)?tok:"/");