It's a new year.
[sgt/putty] / dialog.c
index d9d6aaf..53b6429 100644 (file)
--- a/dialog.c
+++ b/dialog.c
@@ -6,6 +6,7 @@
 #include <assert.h>
 #include <limits.h>
 #include <stdarg.h>
+#include <stdlib.h>
 
 #define DEFINE_INTORPTR_FNS
 
@@ -40,7 +41,7 @@ int ctrl_path_compare(char *p1, char *p2)
 
 struct controlbox *ctrl_new_box(void)
 {
-    struct controlbox *ret = smalloc(sizeof(struct controlbox));
+    struct controlbox *ret = snew(struct controlbox);
 
     ret->nctrlsets = ret->ctrlsetsize = 0;
     ret->ctrlsets = NULL;
@@ -127,7 +128,7 @@ struct controlset *ctrl_settitle(struct controlbox *b,
                                 char *path, char *title)
 {
     
-    struct controlset *s = smalloc(sizeof(struct controlset));
+    struct controlset *s = snew(struct controlset);
     int index = ctrl_find_set(b, path, 1);
     s->pathname = dupstr(path);
     s->boxname = NULL;
@@ -137,8 +138,7 @@ struct controlset *ctrl_settitle(struct controlbox *b,
     s->ctrls = NULL;
     if (b->nctrlsets >= b->ctrlsetsize) {
        b->ctrlsetsize = b->nctrlsets + 32;
-       b->ctrlsets = srealloc(b->ctrlsets,
-                              b->ctrlsetsize*sizeof(*b->ctrlsets));
+       b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
     }
     if (index < b->nctrlsets)
        memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
@@ -161,7 +161,7 @@ struct controlset *ctrl_getset(struct controlbox *b,
            return b->ctrlsets[index];
        index++;
     }
-    s = smalloc(sizeof(struct controlset));
+    s = snew(struct controlset);
     s->pathname = dupstr(path);
     s->boxname = dupstr(name);
     s->boxtitle = boxtitle ? dupstr(boxtitle) : NULL;
@@ -170,8 +170,7 @@ struct controlset *ctrl_getset(struct controlbox *b,
     s->ctrls = NULL;
     if (b->nctrlsets >= b->ctrlsetsize) {
        b->ctrlsetsize = b->nctrlsets + 32;
-       b->ctrlsets = srealloc(b->ctrlsets,
-                              b->ctrlsetsize*sizeof(*b->ctrlsets));
+       b->ctrlsets = sresize(b->ctrlsets, b->ctrlsetsize,struct controlset *);
     }
     if (index < b->nctrlsets)
        memmove(&b->ctrlsets[index+1], &b->ctrlsets[index],
@@ -185,10 +184,14 @@ struct controlset *ctrl_getset(struct controlbox *b,
 void *ctrl_alloc(struct controlbox *b, size_t size)
 {
     void *p;
+    /*
+     * This is an internal allocation routine, so it's allowed to
+     * use smalloc directly.
+     */
     p = smalloc(size);
     if (b->nfrees >= b->freesize) {
        b->freesize = b->nfrees + 32;
-       b->frees = srealloc(b->frees, b->freesize*sizeof(*b->frees));
+       b->frees = sresize(b->frees, b->freesize, void *);
     }
     b->frees[b->nfrees++] = p;
     return p;
@@ -198,10 +201,10 @@ static union control *ctrl_new(struct controlset *s, int type,
                               intorptr helpctx, handler_fn handler,
                               intorptr context)
 {
-    union control *c = smalloc(sizeof(union control));
+    union control *c = snew(union control);
     if (s->ncontrols >= s->ctrlsize) {
        s->ctrlsize = s->ncontrols + 32;
-       s->ctrls = srealloc(s->ctrls, s->ctrlsize * sizeof(*s->ctrls));
+       s->ctrls = sresize(s->ctrls, s->ctrlsize, union control *);
     }
     s->ctrls[s->ncontrols++] = c;
     /*
@@ -229,7 +232,7 @@ union control *ctrl_columns(struct controlset *s, int ncolumns, ...)
     } else {
        va_list ap;
        int i;
-       c->columns.percentages = smalloc(ncolumns * sizeof(int));
+       c->columns.percentages = snewn(ncolumns, int);
        va_start(ap, ncolumns);
        for (i = 0; i < ncolumns; i++)
            c->columns.percentages[i] = va_arg(ap, int);
@@ -293,17 +296,17 @@ union control *ctrl_radiobuttons(struct controlset *s, char *label,
     while (va_arg(ap, char *) != NULL) {
        i++;
        if (c->radio.shortcut == NO_SHORTCUT)
-           va_arg(ap, int);           /* char promotes to int in arg lists */
-       va_arg(ap, intorptr);
+           (void)va_arg(ap, int);     /* char promotes to int in arg lists */
+       (void)va_arg(ap, intorptr);
     }
     va_end(ap);
     c->radio.nbuttons = i;
     if (c->radio.shortcut == NO_SHORTCUT)
-       c->radio.shortcuts = smalloc(c->radio.nbuttons * sizeof(char));
+       c->radio.shortcuts = snewn(c->radio.nbuttons, char);
     else
        c->radio.shortcuts = NULL;
-    c->radio.buttons = smalloc(c->radio.nbuttons * sizeof(char *));
-    c->radio.buttondata = smalloc(c->radio.nbuttons * sizeof(intorptr));
+    c->radio.buttons = snewn(c->radio.nbuttons, char *);
+    c->radio.buttondata = snewn(c->radio.nbuttons, intorptr);
     /*
      * Second pass along variable argument list to actually fill in
      * the structure.
@@ -328,6 +331,7 @@ union control *ctrl_pushbutton(struct controlset *s,char *label,char shortcut,
     c->button.label = label ? dupstr(label) : NULL;
     c->button.shortcut = shortcut;
     c->button.isdefault = 0;
+    c->button.iscancel = 0;
     return c;
 }
 
@@ -358,6 +362,8 @@ union control *ctrl_droplist(struct controlset *s, char *label, char shortcut,
     c->listbox.draglist = 0;
     c->listbox.multisel = 0;
     c->listbox.percentwidth = percentage;
+    c->listbox.ncols = 0;
+    c->listbox.percentages = NULL;
     return c;
 }
 
@@ -372,6 +378,8 @@ union control *ctrl_draglist(struct controlset *s,char *label,char shortcut,
     c->listbox.draglist = 1;
     c->listbox.multisel = 0;
     c->listbox.percentwidth = 100;
+    c->listbox.ncols = 0;
+    c->listbox.percentages = NULL;
     return c;
 }