aboutsummaryrefslogtreecommitdiffstats
path: root/utils/rds-ctl/rds-ctl.cpp
diff options
context:
space:
mode:
authorGregor Jasny <gjasny@googlemail.com>2013-07-22 22:27:02 +0200
committerGregor Jasny <gjasny@googlemail.com>2013-07-31 21:14:47 +0200
commitae5953d21bb371d95cbd4dbeac6c8ca6bed6e007 (patch)
tree8d7115007acd754680859d854f3bc036c83799b6 /utils/rds-ctl/rds-ctl.cpp
parentc6ff5e175bd88fd4e880f0968b0afaa051d63215 (diff)
rds-ctl: Always terminate strings properly
Detected by Coverity. Signed-off-by: Gregor Jasny <gjasny@googlemail.com> Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Diffstat (limited to 'utils/rds-ctl/rds-ctl.cpp')
-rw-r--r--utils/rds-ctl/rds-ctl.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/utils/rds-ctl/rds-ctl.cpp b/utils/rds-ctl/rds-ctl.cpp
index 3db8de8b..621b427d 100644
--- a/utils/rds-ctl/rds-ctl.cpp
+++ b/utils/rds-ctl/rds-ctl.cpp
@@ -762,13 +762,11 @@ static int parse_cl(int argc, char **argv)
params.options[(int)opt] = 1;
switch (opt) {
case OptSetDevice:
- strncpy(params.fd_name, optarg, 80);
+ strncpy(params.fd_name, optarg, sizeof(params.fd_name));
if (optarg[0] >= '0' && optarg[0] <= '9' && strlen(optarg) <= 3) {
- static char newdev[20];
-
- sprintf(newdev, "/dev/radio%s", optarg);
- strncpy(params.fd_name, newdev, 20);
+ snprintf(params.fd_name, sizeof(params.fd_name), "/dev/radio%s", optarg);
}
+ params.fd_name[sizeof(params.fd_name) - 1] = '\0';
break;
case OptSetFreq:
params.freq = strtod(optarg, NULL);
@@ -786,7 +784,8 @@ static int parse_cl(int argc, char **argv)
{
if (access(optarg, F_OK) != -1) {
params.filemode_active = true;
- strncpy(params.fd_name, optarg, 80);
+ strncpy(params.fd_name, optarg, sizeof(params.fd_name));
+ params.fd_name[sizeof(params.fd_name) - 1] = '\0';
} else {
fprintf(stderr, "Unable to open file: %s\n", optarg);
return -1;
@@ -993,7 +992,8 @@ int main(int argc, char **argv)
fprintf(stderr, "No RDS-capable device found\n");
exit(1);
}
- strncpy(params.fd_name, devices[0].c_str(), 80);
+ strncpy(params.fd_name, devices[0].c_str(), sizeof(params.fd_name));
+ params.fd_name[sizeof(params.fd_name) - 1] = '\0';
printf("Using device: %s\n", params.fd_name);
}
if ((fd = test_open(params.fd_name, O_RDONLY | O_NONBLOCK)) < 0) {

Privacy Policy