summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.c15
-rw-r--r--src/config.h1
-rw-r--r--src/note_list.c2
3 files changed, 10 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index a8c83d2..c3509cc 100644
--- a/src/config.c
+++ b/src/config.c
@@ -43,8 +43,8 @@ int config_new(config_t* conf, char* p) {
}
// Set the maximum read width and read buffer array
- int len = 120;
- char buf[len];
+ int len = config_line_len;
+ char buf[config_line_len] = "";
char key[32];
char value[256];
@@ -74,7 +74,8 @@ int config_new(config_t* conf, char* p) {
end++;
}
- char tmp_line[end - start + 10];
+ //char tmp_line[end - start + 10];
+ char tmp_line[config_line_len] = "";
// Temp variable to store the text between index start and index end
strncpy(tmp_line, &buf[start], end - start + 1);
// Make sure it has a trailing newline so sscanf works
@@ -86,8 +87,8 @@ int config_new(config_t* conf, char* p) {
// Allocate heap memory for values since these need to persist.
// Note that here we are using the temp variables to establish string
// length for when we allocate heap memory.
- conf->keys[i] = malloc(sizeof(char) * strlen(key));
- conf->values[i] = malloc(sizeof(char) * strlen(value));
+ conf->keys[i] = malloc(sizeof(char) * (strlen(key) + 1));
+ conf->values[i] = malloc(sizeof(char) * (strlen(value) + 1));
// Copy in the temp values
strcpy(conf->keys[i], key);
@@ -134,8 +135,8 @@ int config_valid_line_count(char* path) {
FILE* f;
f = fopen(path, "r");
- int len = 120;
- char buf[len];
+ int len = config_line_len;
+ char buf[config_line_len];
while(fgets(buf, len, f) != NULL) {
int start = 0;
diff --git a/src/config.h b/src/config.h
index 2a3e0d0..295969d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -18,6 +18,7 @@
*/
#ifndef NOTELESS_CONFIG_H
#define NOTELESS_CONFIG_H
+#define config_line_len 120
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/note_list.c b/src/note_list.c
index 79b9aa9..2566b59 100644
--- a/src/note_list.c
+++ b/src/note_list.c
@@ -58,7 +58,7 @@ void note_list_new(note_list_t* list, char* path, char* ext) {
// Allocate space for the entire filename (we'll strip the extension off
// as needed later). This will make calculating path lengths much
// simpler.
- list->names[i] = malloc(sizeof(char) * strlen(ent->d_name));
+ list->names[i] = malloc(sizeof(char) * (strlen(ent->d_name) + 1));
// Copy the filename into the struct
strcpy(list->names[i], ent->d_name);

Generated by cgit