refactor: strncpy -> strlcpy
This commit is contained in:
+8
-7
@@ -1,3 +1,4 @@
|
||||
#include <bsd/string.h>
|
||||
#include <limits.h>
|
||||
#include <log.h>
|
||||
#include <stdbool.h>
|
||||
@@ -105,8 +106,8 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
char *arg;
|
||||
char *value;
|
||||
|
||||
strncpy(params->project_path, DATADIR "/default", STR_LEN);
|
||||
strncpy(params->config_file, "forge_project.cfg", STR_LEN);
|
||||
strlcpy(params->project_path, DATADIR "/default", STR_LEN);
|
||||
strlcpy(params->config_file, "forge_project.cfg", STR_LEN);
|
||||
params->hot_reload = false;
|
||||
params->output = true;
|
||||
params->output_screen = 0;
|
||||
@@ -119,7 +120,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
params->video_in.length = 0;
|
||||
params->video_size = 0;
|
||||
params->internal_size = 720;
|
||||
strncpy(params->state_file, "forge_saved_state.txt", STR_LEN);
|
||||
strlcpy(params->state_file, "forge_saved_state.txt", STR_LEN);
|
||||
params->load_state = true;
|
||||
params->save_state = true;
|
||||
params->trace_midi = false;
|
||||
@@ -134,9 +135,9 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
puts(PACKAGE " " VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (is_arg(arg, "-p") || is_arg(arg, "--project")) {
|
||||
strncpy(params->project_path, value, STR_LEN);
|
||||
strlcpy(params->project_path, value, STR_LEN);
|
||||
} else if (is_arg(arg, "-c") || is_arg(arg, "--config")) {
|
||||
strncpy(params->config_file, value, STR_LEN);
|
||||
strlcpy(params->config_file, value, STR_LEN);
|
||||
} else if (is_arg(arg, "-hr") || is_arg(arg, "--hot-reload")) {
|
||||
params->hot_reload = true;
|
||||
} else if (is_arg(arg, "-s") || is_arg(arg, "--screen")) {
|
||||
@@ -165,7 +166,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
log_error("maximum video input reached");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
strncpy(params->video_in.values[params->video_in.length++], value,
|
||||
strlcpy(params->video_in.values[params->video_in.length++], value,
|
||||
STR_LEN);
|
||||
} else if (is_arg(arg, "-vs") || is_arg(arg, "--video-size")) {
|
||||
params->video_size = parse_uint(arg, value);
|
||||
@@ -178,7 +179,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
|
||||
invalid_value(arg, value);
|
||||
}
|
||||
} else if (is_arg(arg, "-sf") || is_arg(arg, "--state-file")) {
|
||||
strncpy(params->state_file, value, STR_LEN);
|
||||
strlcpy(params->state_file, value, STR_LEN);
|
||||
} else if (is_arg(arg, "-ls") || is_arg(arg, "--load-state")) {
|
||||
params->load_state = true;
|
||||
} else if (is_arg(arg, "-nls") || is_arg(arg, "--no-load-state")) {
|
||||
|
||||
+5
-4
@@ -1,3 +1,4 @@
|
||||
#include <bsd/string.h>
|
||||
#include <hashmap.h>
|
||||
#include <log.h>
|
||||
#include <stdlib.h>
|
||||
@@ -52,11 +53,11 @@ static void parse_config_file_line(ConfigFile *config, char *line) {
|
||||
key_size = equal_pos - line;
|
||||
value_size = size - key_size - 1;
|
||||
|
||||
strncpy(item.key, line, key_size);
|
||||
strlcpy(item.key, line, key_size + 1);
|
||||
item.key[key_size] = '\0';
|
||||
|
||||
if (value_size > 0) {
|
||||
strncpy(item.value, line + key_size + 1, value_size);
|
||||
strlcpy(item.value, line + key_size + 1, value_size + 1);
|
||||
item.value[value_size] = '\0';
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ char *config_file_get_str(ConfigFile *config, char *key, char *default_value) {
|
||||
ConfigFileItem c_key;
|
||||
ConfigFileItem *item;
|
||||
|
||||
strncpy(c_key.key, key, STR_LEN);
|
||||
strlcpy(c_key.key, key, STR_LEN);
|
||||
|
||||
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
||||
|
||||
@@ -106,7 +107,7 @@ unsigned int config_file_get_int(ConfigFile *config, char *key,
|
||||
ConfigFileItem c_key;
|
||||
ConfigFileItem *item;
|
||||
|
||||
strncpy(c_key.key, key, STR_LEN);
|
||||
strlcpy(c_key.key, key, STR_LEN);
|
||||
|
||||
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
||||
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
#include <bsd/string.h>
|
||||
#include <log.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -68,7 +69,7 @@ bool file_update(File *file) {
|
||||
}
|
||||
|
||||
void file_read(File *file, char *path) {
|
||||
strncpy(file->path, path, STR_LEN);
|
||||
strlcpy(file->path, path, STR_LEN);
|
||||
file->content = NULL;
|
||||
file->error = false;
|
||||
file->last_write = 0;
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <bsd/string.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
@@ -7,7 +8,7 @@
|
||||
#include "log.h"
|
||||
|
||||
void midi_open(MidiDevice *device, char *name) {
|
||||
strncpy(device->name, name, STR_LEN);
|
||||
strlcpy(device->name, name, STR_LEN);
|
||||
device->input = NULL;
|
||||
device->output = NULL;
|
||||
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ void project_init(Project *project, char *project_path, char *config_file) {
|
||||
char *frag_prefix;
|
||||
unsigned int i;
|
||||
|
||||
strncpy(project->path, project_path, STR_LEN);
|
||||
strlcpy(project->path, project_path, STR_LEN);
|
||||
|
||||
snprintf(config_path, STR_LEN, "%s/%s", project_path, config_file);
|
||||
|
||||
|
||||
+2
-2
@@ -63,8 +63,8 @@ char *string_replace_at(char *src, unsigned int from, unsigned int to,
|
||||
|
||||
dst = malloc(src_len - (to - from) + rpl_len + 1);
|
||||
|
||||
strncpy(dst, src, from);
|
||||
strncpy(dst + from, rpl, rpl_len);
|
||||
strlcpy(dst, src, from + 1);
|
||||
strlcpy(dst + from, rpl, rpl_len + 1);
|
||||
strlcpy(dst + from + rpl_len, src + to, src_len - to + 1);
|
||||
|
||||
return dst;
|
||||
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
#include <bsd/string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/videodev2.h>
|
||||
@@ -66,7 +67,7 @@ static void ioctl_error(VideoCapture *video_capture, const char *operation,
|
||||
}
|
||||
|
||||
static void open_device(VideoCapture *video_capture, char *name) {
|
||||
strncpy(video_capture->name, name, STR_LEN);
|
||||
strlcpy(video_capture->name, name, STR_LEN);
|
||||
video_capture->error = false;
|
||||
video_capture->fd = -1;
|
||||
video_capture->exp_fd = -1;
|
||||
|
||||
Reference in New Issue
Block a user