Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/uniq asprintf is easier and safer



details:   https://anonhg.NetBSD.org/src/rev/3f6ac9b85f05
branches:  trunk
changeset: 549425:3f6ac9b85f05
user:      itojun <itojun%NetBSD.org@localhost>
date:      Mon Jul 14 09:29:21 2003 +0000

description:
asprintf is easier and safer

diffstat:

 usr.bin/uniq/uniq.c |  13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diffs (42 lines):

diff -r 14d7218e72a6 -r 3f6ac9b85f05 usr.bin/uniq/uniq.c
--- a/usr.bin/uniq/uniq.c       Mon Jul 14 09:25:37 2003 +0000
+++ b/usr.bin/uniq/uniq.c       Mon Jul 14 09:29:21 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uniq.c,v 1.9 1998/12/19 23:23:49 christos Exp $        */
+/*     $NetBSD: uniq.c,v 1.10 2003/07/14 09:29:21 itojun Exp $ */
 
 /*
  * Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)uniq.c     8.3 (Berkeley) 5/4/95";
 #endif
-__RCSID("$NetBSD: uniq.c,v 1.9 1998/12/19 23:23:49 christos Exp $");
+__RCSID("$NetBSD: uniq.c,v 1.10 2003/07/14 09:29:21 itojun Exp $");
 #endif /* not lint */
 
 #include <err.h>
@@ -220,7 +220,6 @@
 obsolete(argv)
        char *argv[];
 {
-       int len;
        char *ap, *p, *start;
 
        while ((ap = *++argv) != NULL) {
@@ -236,12 +235,10 @@
                 * Digit signifies an old-style option.  Malloc space for dash,
                 * new option and argument.
                 */
-               len = strlen(ap);
-               if ((start = p = malloc(len + 3)) == NULL)
+               asprintf(&p, "-%c%s", ap[0] == '+' ? 's' : 'f', ap + 1);
+               if (!p)
                        err(1, "malloc");
-               *p++ = '-';
-               *p++ = ap[0] == '+' ? 's' : 'f';
-               (void)strcpy(p, ap + 1);
+               start = p;
                *argv = start;
        }
 }



Home | Main Index | Thread Index | Old Index