refactor: strlen -> strnlen
This commit is contained in:
+3
-3
@@ -27,7 +27,7 @@ static uint64_t item_hash(const void *item, uint64_t seed0, uint64_t seed1) {
|
|||||||
|
|
||||||
c_item = item;
|
c_item = item;
|
||||||
|
|
||||||
return hashmap_sip(c_item->key, strlen(c_item->key), seed0, seed1);
|
return hashmap_sip(c_item->key, strnlen(c_item->key, STR_LEN), seed0, seed1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_config_file_line(ConfigFile *config, char *line) {
|
static void parse_config_file_line(ConfigFile *config, char *line) {
|
||||||
@@ -95,7 +95,7 @@ char *config_file_get_str(ConfigFile *config, char *key, char *default_value) {
|
|||||||
|
|
||||||
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
||||||
|
|
||||||
if (item == NULL || strlen(item->value) == 0) {
|
if (item == NULL || strnlen(item->value, STR_LEN) == 0) {
|
||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ unsigned int config_file_get_int(ConfigFile *config, char *key,
|
|||||||
|
|
||||||
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
item = (ConfigFileItem *)hashmap_get(config->map, &c_key);
|
||||||
|
|
||||||
if (item == NULL || strlen(item->value) == 0) {
|
if (item == NULL || strnlen(item->value, STR_LEN) == 0) {
|
||||||
return default_value;
|
return default_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -44,12 +44,12 @@ static void compute_fps(bool trace_fps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window_output != NULL) {
|
if (window_output != NULL) {
|
||||||
sprintf(title, PACKAGE " " VERSION " - %.0ffps", fps);
|
snprintf(title, STR_LEN, PACKAGE " " VERSION " - %.0ffps", fps);
|
||||||
window_update_title(window_output, title);
|
window_update_title(window_output, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window_monitor != NULL) {
|
if (window_monitor != NULL) {
|
||||||
sprintf(title, PACKAGE " " VERSION " (monitor) - %.0ffps", fps);
|
snprintf(title, STR_LEN, PACKAGE " " VERSION " (monitor) - %.0ffps", fps);
|
||||||
window_update_title(window_monitor, title);
|
window_update_title(window_monitor, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -3,6 +3,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
unsigned int string_trim(char *str) {
|
unsigned int string_trim(char *str) {
|
||||||
@@ -11,7 +12,7 @@ unsigned int string_trim(char *str) {
|
|||||||
unsigned int end;
|
unsigned int end;
|
||||||
|
|
||||||
start = 0;
|
start = 0;
|
||||||
end = strlen(str) - 1;
|
end = strnlen(str, STR_LEN) - 1;
|
||||||
|
|
||||||
if (end == 0) {
|
if (end == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -28,7 +29,7 @@ unsigned int string_trim(char *str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the string was trimmed, adjust the null terminator
|
// If the string was trimmed, adjust the null terminator
|
||||||
if (start > 0 || end < (strlen(str) - 1)) {
|
if (start > 0 || end < (strnlen(str, STR_LEN) - 1)) {
|
||||||
memmove(str, str + start, end - start + 1);
|
memmove(str, str + start, end - start + 1);
|
||||||
str[end - start + 1] = '\0';
|
str[end - start + 1] = '\0';
|
||||||
}
|
}
|
||||||
@@ -44,7 +45,7 @@ bool string_is_number(char *value) {
|
|||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
value_len = strlen(value);
|
value_len = strnlen(value, STR_LEN);
|
||||||
for (i = 0; i < value_len; i++) {
|
for (i = 0; i < value_len; i++) {
|
||||||
if (!is_digit(value[i])) {
|
if (!is_digit(value[i])) {
|
||||||
return false;
|
return false;
|
||||||
@@ -58,8 +59,8 @@ char *string_replace_at(char *src, unsigned int from, unsigned int to,
|
|||||||
unsigned long src_len, rpl_len;
|
unsigned long src_len, rpl_len;
|
||||||
char *dst;
|
char *dst;
|
||||||
|
|
||||||
src_len = strlen(src);
|
src_len = strnlen(src, STR_LEN * STR_LEN);
|
||||||
rpl_len = strlen(rpl);
|
rpl_len = strnlen(rpl, STR_LEN * STR_LEN);
|
||||||
|
|
||||||
dst = malloc(src_len - (to - from) + rpl_len + 1);
|
dst = malloc(src_len - (to - from) + rpl_len + 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user