]> git.deb.at Git - pkg/abook.git/commitdiff
Fixed snprintf related bugs
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Mon, 11 Jun 2001 12:51:54 +0000 (12:51 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Mon, 11 Jun 2001 12:51:54 +0000 (12:51 +0000)
ChangeLog
abook.c
edit.c
misc.c

index da9f81a88b10a4a0604af4d5aa89c498468aaf53..42dd5a16a87de350eb23459578fde15ac8412fe7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
  - new editor commands
  - text filter update
  - query/find code cleanup
+ - fixed snprintf related bugs
 
 0.4.12
  - added man page for abookrc (Alan Ford)
diff --git a/abook.c b/abook.c
index e01eb427b4a399e78dda5f616191ae5b8a310240..6147aeeadcd28fabb98d341222e614e397e0cf4a 100644 (file)
--- a/abook.c
+++ b/abook.c
@@ -204,7 +204,6 @@ show_usage()
 }
 
 extern list_item *database;
-extern int items;
 
 static void
 muttq_print_item(int item)
@@ -277,23 +276,23 @@ quit_mutt_query(int status)
 void
 launch_mutt(int item)
 {
-       int i;
+       /*
+        * This is _broken_
+        */
+#if 0
+       struct db_enumerator e = init_db_enumerator(ENUM_ALL);
        char email[MAX_EMAIL_LEN];
        char *cmd;
        char *tmp = options_get_str("mutt_command");
 
-       if( !is_valid_item(item) )
-               return;
-
        cmd = strconcat(tmp, " '", NULL );
 
-       for(i=0; i < items; i++) {
-               if( ! is_selected(i) && i != list_current_item() )
-                       continue;
-               get_first_email(email, i);
-               tmp = mkstr("%s \"%s\"", cmd, database[i][NAME]);
+       db_enumerate_items(e) {
+               if( e.item != item );
+               get_first_email(email, e.item);
+               tmp = mkstr("%s, \"%s\"", cmd, database[e.item][NAME]);
                my_free(cmd);
-               if( *database[i][EMAIL] ) {
+               if( *database[e.item][EMAIL] ) {
                        cmd = mkstr("%s <%s>", tmp, email);
                        free(tmp);
                        tmp = cmd;
@@ -302,7 +301,7 @@ launch_mutt(int item)
                free(tmp);
        }
 
-       tmp = mkstr("%s%c", cmd, '\'');
+       tmp = strconcat(cmd, "\'", NULL);
        free(cmd);
        cmd = tmp;
 #ifdef DEBUG
@@ -311,6 +310,7 @@ launch_mutt(int item)
        system(cmd);    
 
        free(cmd);
+#endif
 }
 
 void
diff --git a/edit.c b/edit.c
index e41d707d1d5d22e6f87a75cbdd4a80031d541635..feb59bebc6012de11663ac995654a26aa4352176 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -127,12 +127,12 @@ print_editor_header(int item)
 
        get_first_email(email, item);
        
-       if( snprintf(header, EDITW_COLS, "%s <%s>", database[item][NAME],
-                               email ) ==  -1 || !*database[item][EMAIL] )
-       if( snprintf(header, EDITW_COLS, "%s", database[item][NAME]) == -1) {
-               free(header);
-               return;
-       }
+       if( *database[item][EMAIL] )
+               snprintf(header, EDITW_COLS, "%s <%s>",
+                               database[item][NAME],
+                               database[item][EMAIL]);
+       else
+               snprintf(header, EDITW_COLS, "%s", database[item][NAME]);
 
        len = strlen(header);
        x = (EDITW_COLS - len) / 2;
diff --git a/misc.c b/misc.c
index eae1e90178b37ee344fa4f16766936118b6a4137..1213dd57297d734797f3cc1c6d5ab3de91b1e2e1 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -123,10 +123,13 @@ mkstr (const char *format, ... )
                                format, ap);
                MY_VA_END;
 
-               if (n > -1)
+               if (n > -1 && n < size)
                        return buffer;
 
-               size *= 2;
+               if (n > -1)
+                       size = n + 1;
+               else
+                       size *= 2;
                
                buffer =
 #ifdef ABOOK_SRC