From d19e340acfe452aafc521dbe8234065f0ccd0b7f Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sun, 8 Jan 2023 00:00:08 -0600 Subject: [PATCH] Sun Jan 8 12:00:08 AM CST 2023 automatic backup --- actions.c | 3 ++- function.c | 7 ++++--- odot.c | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/actions.c b/actions.c index 2fc6254..4a5e10b 100644 --- a/actions.c +++ b/actions.c @@ -11,7 +11,8 @@ extern int exists, showdone; void newtask(sqlite3 *db){ - char *cmd = malloc(MAXLINE*sizeof(char)); + int len = 45+strlen(group)+strlen(task); + char *cmd = malloc(len*sizeof(char)); if (exists == 0){ sprintf(cmd,"%s (%i, '%s', '%s', 0);",INSERT,hash,task,group); diff --git a/function.c b/function.c index 0421ebb..3019700 100644 --- a/function.c +++ b/function.c @@ -22,7 +22,7 @@ int genhash(char *str) { char *filepath(void){ char *dir = getenv("XDG_DATA_HOME"); - char *db = malloc(MAXLINE * sizeof(char)); + char *database = malloc(MAXLINE * sizeof(char)); /* set dir to $HOME/.local/share if XDG isn't set */ if (!dir) { @@ -42,9 +42,10 @@ char *filepath(void){ if (err) error(DIRERR); } - sprintf(db,"%s/odot.db",dir); + sprintf(database,"%s/odot.db",dir); + free(dir); - return db; + return database; } void checksame(char *task,char *oldgroup){ diff --git a/odot.c b/odot.c index df155be..539f548 100644 --- a/odot.c +++ b/odot.c @@ -19,8 +19,14 @@ int main(int argc, char *argv[]){ int err = 0; sqlite3 *db; - err = sqlite3_open(filepath(),&db); + + char *dbpath = malloc(MAXLINE*sizeof(char)); + dbpath = filepath(); + err = sqlite3_open(dbpath,&db); + free(dbpath); + if (err < 0) sqlerror(db); + sqlcmd(db,BUILDTABLE,'c'); /* show all tasks if called alone */ -- 2.44.2