Vadim Zhukov wrote:
> 2016-01-22 23:18 GMT+03:00 Martijn van Duren 
> <openbsd+t...@list.imperialat.at>:
> > 5) 5_vi_remove_v_strdup.diff: Use strdup instead of v_strdup.
> 
> Not okay: MALLOC macro prints information message to user, while
> patched version isn't. I think refactoring shouldn't have such visible
> impact on functionality, to make sure nothing breaks.

On the subject of the allocation macros:

 o maybe we should wrap them in do { ... } while (0) for safety's sake

 o I got the *_NOMSG removals upstreamed. Is the below diff ok? No
   binary change.


Index: cl/cl_main.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/cl/cl_main.c,v
retrieving revision 1.28
diff -u -p -r1.28 cl_main.c
--- cl/cl_main.c        28 Dec 2015 19:24:01 -0000      1.28
+++ cl/cl_main.c        23 Jan 2016 06:40:49 -0000
@@ -151,7 +151,7 @@ gs_init(char *name)
                name = p + 1;
 
        /* Allocate the global structure. */
-       CALLOC_NOMSG(NULL, gp, 1, sizeof(GS));
+       gp = calloc(1, sizeof(GS));
        if (gp == NULL)
                err(1, NULL);
 
@@ -171,7 +171,7 @@ cl_init(GS *gp)
        int fd;
 
        /* Allocate the CL private structure. */
-       CALLOC_NOMSG(NULL, clp, 1, sizeof(CL_PRIVATE));
+       clp = calloc(1, sizeof(CL_PRIVATE));
        if (clp == NULL)
                err(1, NULL);
        gp->cl_private = clp;
Index: common/main.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/main.c,v
retrieving revision 1.33
diff -u -p -r1.33 main.c
--- common/main.c       9 Jan 2016 16:13:26 -0000       1.33
+++ common/main.c       23 Jan 2016 06:40:49 -0000
@@ -361,7 +361,7 @@ editor(GS *gp, int argc, char *argv[])
                        size_t l;
                        /* Cheat -- we know we have an extra argv slot. */
                        l = strlen(sp->frp->name) + 1;
-                       MALLOC_NOMSG(sp, *--argv, l);
+                       *--argv = malloc(l);
                        if (*argv == NULL) {
                                v_estr(gp->progname, errno, NULL);
                                goto err;
@@ -561,7 +561,7 @@ v_obsolete(char *name, char *argv[])
                        } else  {
                                p = argv[0];
                                len = strlen(argv[0]);
-                               MALLOC_NOMSG(NULL, argv[0], len + 2);
+                               argv[0] = malloc(len + 2);
                                if (argv[0] == NULL)
                                        goto nomem;
                                argv[0][0] = '-';
Index: common/mem.h
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/mem.h,v
retrieving revision 1.7
diff -u -p -r1.7 mem.h
--- common/mem.h        7 Dec 2015 20:39:19 -0000       1.7
+++ common/mem.h        23 Jan 2016 06:40:49 -0000
@@ -120,9 +120,6 @@
        if (((p) = calloc((nmemb), (size))) == NULL)                    \
                goto alloc_err;                                         \
 }
-#define        CALLOC_NOMSG(sp, p, nmemb, size) {                              
\
-       (p) = calloc((nmemb), (size));                                  \
-}
 #define        CALLOC_RET(sp, p, nmemb, size) {                                
\
        if (((p) = calloc((nmemb), (size))) == NULL) {                  \
                msgq((sp), M_SYSERR, NULL);                             \
@@ -137,9 +134,6 @@
 #define        MALLOC_GOTO(sp, p, size) {                                      
\
        if (((p) = malloc(size)) == NULL)                               \
                goto alloc_err;                                         \
-}
-#define        MALLOC_NOMSG(sp, p, size) {                                     
\
-       (p) = malloc(size);                                             \
 }
 #define        MALLOC_RET(sp, p, size) {                                       
\
        if (((p) = malloc(size)) == NULL) {                             \

Reply via email to