char key_internal[KEY_MAX];
size_t key_internal_len;
char buf[PATH_MAX];
+ size_t value_internal_len;
char *ptr;
FILE *fp = NULL;
key_internal_len = strlen(key_internal);
while ((ptr = fgets(buf, sizeof(buf), fp))) {
if (!strncmp(buf, key_internal, key_internal_len) && buf[key_internal_len] == ' ') {
- sscanf(buf, "%*s %[^\n]s", value);
+ value_internal_len = strcspn(buf + key_internal_len + 1, "\n") + 1;
+ snprintf(value, val_len < value_internal_len ? val_len : value_internal_len,
+ "%s", buf + key_internal_len + 1);
break;
}
}
char value_intg[LANG_MAX + 1] = {0};
int ret;
- ret = db_get_value(db_path, tag, name, type, value_intg, LANG_MAX);
+ ret = db_get_value(db_path, tag, name, type, value_intg, LANG_MAX + 1);
if (ret != 0)
return ret;
char key_internal[KEY_MAX];
size_t key_internal_len;
char buf[PATH_MAX]; // buffer size should be larger than KEY_MAX
+ size_t value_internal_len;
FILE *fp = NULL;
int ret;
char *tag_s;
key_internal_len = strlen(key_internal);
while ((temp = fgets(buf, sizeof(buf), fp))) {
if (!strncmp(buf, key_internal, key_internal_len) && buf[key_internal_len] == ' ') {
- sscanf(buf, "%*s %[^\n]s", value);
+ value_internal_len = strcspn(buf + key_internal_len + 1, "\n") + 1;
+ snprintf(value, len < value_internal_len ? len : value_internal_len,
+ "%s", buf + key_internal_len + 1);
break;
}
}