Commit 95ed6ec8 authored by Federico Vaga's avatar Federico Vaga

sw: apply some flawfinder suggestions

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 20c8e332
......@@ -96,7 +96,7 @@ struct fdelay_board *fdelay_open(int dev_id)
goto err_stat_d;
if (!S_ISCHR(sb.st_mode))
goto err_stat_d;
b->devbase = strndup(path, strlen(path) - strlen("-0-0-ctrl"));
b->devbase = strndup(path, strnlen(path, sizeof(path)) - strlen("-0-0-ctrl"));
ret = fdelay_sysfs_get(b, "version", &v);
if (ret)
......
......@@ -198,7 +198,7 @@ static inline int fdelay_sysfs_get(struct __fdelay_board *b, char *name,
{
char pathname[128];
sprintf(pathname, "%s/%s", b->sysbase, name);
snprintf(pathname, sizeof(pathname), "%s/%s", b->sysbase, name);
return __fdelay_sysfs_get(pathname, resp);
}
......@@ -207,7 +207,7 @@ static inline int fdelay_sysfs_set(struct __fdelay_board *b, char *name,
{
char pathname[128];
sprintf(pathname, "%s/%s", b->sysbase, name);
snprintf(pathname, sizeof(pathname), "%s/%s", b->sysbase, name);
return __fdelay_sysfs_set(pathname, value);
}
......
......@@ -68,7 +68,7 @@ static int __fdelay_get_ch_fd(struct __fdelay_board *b,
if (b->fdc[ch14] <= 0) {
char fname[128];
sprintf(fname, "%s-%i-0-ctrl", b->devbase, ch14);
snprintf(fname, sizeof(fname), "%s-%i-0-ctrl", b->devbase, ch14);
b->fdc[ch14] = open(fname, O_WRONLY | O_NONBLOCK);
if (b->fdc[ch14] < 0)
return -1;
......@@ -226,51 +226,51 @@ int fdelay_get_config_pulse(struct fdelay_board *userb,
memset(pulse, 0, sizeof(struct fdelay_pulse));
sprintf(s,"fd-ch%i/%s", channel + 1, "mode");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "mode");
if (fdelay_sysfs_get(b, s, &tmp) < 0)
return -1; /* errno already set */
pulse->mode = tmp;
sprintf(s,"fd-ch%i/%s", channel + 1, "rep");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "rep");
if (fdelay_sysfs_get(b, s, &tmp) < 0)
return -1;
pulse->rep = tmp;
sprintf(s,"fd-ch%i/%s", channel + 1, "start-h");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "start-h");
if (fdelay_sysfs_get(b, s, &utc_h) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "start-l");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "start-l");
if (fdelay_sysfs_get(b, s, &utc_l) < 0)
return -1;
pulse->start.utc = (((uint64_t)utc_h) << 32) | utc_l;
sprintf(s,"fd-ch%i/%s", channel + 1, "start-coarse");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "start-coarse");
if (fdelay_sysfs_get(b, s, &pulse->start.coarse) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "start-fine");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "start-fine");
if (fdelay_sysfs_get(b, s, &pulse->start.frac) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "end-h");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "end-h");
if (fdelay_sysfs_get(b, s, &utc_h) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "end-l");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "end-l");
if (fdelay_sysfs_get(b, s, &utc_l) < 0)
return -1;
pulse->end.utc = (((uint64_t)utc_h) << 32) | utc_l;
sprintf(s,"fd-ch%i/%s", channel + 1, "end-coarse");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "end-coarse");
if (fdelay_sysfs_get(b, s, &pulse->end.coarse) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "end-fine");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "end-fine");
if (fdelay_sysfs_get(b, s, &pulse->end.frac) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "delta-l");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "delta-l");
if (fdelay_sysfs_get(b, s, &utc_l) < 0)
return -1;
pulse->loop.utc = utc_l;
sprintf(s,"fd-ch%i/%s", channel + 1, "delta-coarse");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "delta-coarse");
if (fdelay_sysfs_get(b, s, &pulse->loop.coarse) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "delta-fine");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "delta-fine");
if (fdelay_sysfs_get(b, s, &pulse->loop.frac) < 0)
return -1;
......@@ -278,15 +278,15 @@ int fdelay_get_config_pulse(struct fdelay_board *userb,
* Now, to return consistent values to the user, we must
* un-apply all offsets that the driver added
*/
sprintf(s,"fd-ch%i/%s", channel + 1, "delay-offset");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "delay-offset");
if (fdelay_sysfs_get(b, s, &output_offset) < 0)
return -1;
sprintf(s,"fd-ch%i/%s", channel + 1, "user-offset");
snprintf(s, sizeof(s), "fd-ch%i/%s", channel + 1, "user-offset");
if (fdelay_sysfs_get(b, s, &output_user_offset) < 0)
return -1;
sprintf(s,"fd-input/%s", "offset");
snprintf(s, sizeof(s), "fd-input/%s", "offset");
if (fdelay_sysfs_get(b, s, &input_offset) < 0)
return -1;
......@@ -365,7 +365,7 @@ int fdelay_has_triggered(struct fdelay_board *userb, int channel)
char s[32];
uint32_t mode;
sprintf(s,"fd-ch%i/mode", channel + 1);
snprintf(s, sizeof(s), "fd-ch%i/mode", channel + 1);
if (fdelay_sysfs_get(b, s, &mode) < 0)
return -1; /* errno already set */
return (mode & 0x80) != 0;
......
......@@ -70,7 +70,7 @@ static int __fdelay_open_tdc(struct __fdelay_board *b)
if (b->fdc[0] <= 0) {
char fname[128];
sprintf(fname, "%s-0-0-ctrl", b->devbase);
snprintf(fname, sizeof(fname), "%s-0-0-ctrl", b->devbase);
b->fdc[0] = open(fname, O_RDONLY | O_NONBLOCK);
}
return b->fdc[0];
......
......@@ -135,7 +135,7 @@ static int fmc_fdelay_calibration_write(unsigned int devid, struct fd_calibratio
int fd;
int ret;
sprintf(path,
snprintf(path, sizeof(path),
"/sys/bus/zio/devices/fd-%04x/calibration_data",
devid);
......
......@@ -8,6 +8,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <inttypes.h>
#include <time.h>
#include "fdelay-lib.h"
......@@ -398,7 +399,12 @@ int main(int argc, char **argv)
exit(1);
}
while (trigger_wait) {
usleep(10 * 1000);
struct timespec ts = {
.tv_sec = 0,
.tv_nsec = 10 * 1000,
};
nanosleep(&ts, NULL);
i = fdelay_has_triggered(b, channel);
if (i < 0) {
fprintf(stderr, "%s: waiting for trigger: %s\n",
......
......@@ -158,13 +158,13 @@ void report_output_config_raw(int channel, struct fdelay_pulse *p, int umode)
char mode[80];
int m = p->mode & 0x7f;
if (m == FD_OUT_MODE_DISABLED) strcpy(mode, "disabled");
else if (m == FD_OUT_MODE_PULSE) strcpy(mode, "pulse");
else if (m == FD_OUT_MODE_DELAY) strcpy(mode, "delay");
else sprintf(mode, "%i (0x%04x)", p->mode, p->mode);
if (m == FD_OUT_MODE_DISABLED) strncpy(mode, "disabled", sizeof(mode));
else if (m == FD_OUT_MODE_PULSE) strncpy(mode, "pulse", sizeof(mode));
else if (m == FD_OUT_MODE_DELAY) strncpy(mode, "delay", sizeof(mode));
else snprintf(mode, sizeof(mode), "%i (0x%04x)", p->mode, p->mode);
if (p->mode & 0x80)
strcat(mode, " (triggered)");
strncat(mode, " (triggered)", sizeof(mode) - strlen(mode));
printf("Channel %i, mode %s, repeat %i %s\n",
FDELAY_OUTPUT_HW_TO_USER(channel), mode,
p->rep, p->rep == -1 ? "(infinite)" : "");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment