optimization on memory
This commit is contained in:
parent
0e3dd1a83f
commit
fe1de151ff
4 changed files with 14 additions and 5 deletions
|
@ -111,6 +111,11 @@ int suggest_command(char *command, char *command_re, hashmap *polls,
|
|||
}
|
||||
page[strlen(page) - 1] = '\0';
|
||||
|
||||
if (strstr(page,"\n") || strstr(page,";") || strstr(page,",") || strstr(page,"+")) {
|
||||
printf("This element contains illegal characters.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *val = calloc(MAX_BUF_LENGTH, sizeof(char));
|
||||
sprintf(val, "%s;%s", page, command_re);
|
||||
|
||||
|
|
11
src/loader.c
11
src/loader.c
|
@ -32,12 +32,15 @@ int load_elements(hashmap *m, char *table, int use_inv) {
|
|||
continue;
|
||||
}
|
||||
|
||||
char *combo = strstr(str, ";");
|
||||
combo[0] = '\0';
|
||||
combo++;
|
||||
char *combo_o = strstr(str, ";");
|
||||
combo_o[0] = '\0';
|
||||
combo_o++;
|
||||
|
||||
char *combo = calloc(strlen(combo_o)+1,sizeof(char));
|
||||
strcpy(combo,combo_o);
|
||||
|
||||
if (use_inv == 2) {
|
||||
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 0);
|
||||
hashmap_set(m, str, strlen(str) - 1, (uintptr_t)combo, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ void init_tables(hashmap *elements, hashmap *inv, hashmap *polls, int do_inv) {
|
|||
load_elements(inv, inv_file, 1);
|
||||
}
|
||||
|
||||
// todo: sanitize, valgrind, look through todos
|
||||
int main(int argc, char *argv[]) {
|
||||
char *name;
|
||||
if (argc < 2) {
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
#define MAX_BUF_LENGTH 1024
|
||||
#define MAX_COMBO_LENGTH 1024
|
||||
#define UPVOTE_IN 2
|
||||
#define MAX_FILE_SIZE 1024 * 16
|
||||
#define MAX_FILE_SIZE 1024
|
||||
long stoi(const char *s);
|
Loading…
Reference in a new issue