Re: [patch]rcs: xstrdup just wrappes strdup
On Mon, Jun 15, 2015 at 10:22:27AM +0100, Nicholas Marriott wrote: What about diff and ssh and file? They all use the a copy of the same xmalloc.c. Personally, I would recommend that xstrdup just calls strdup(3), as Theo said: it's 100.00% portable. But I don't think I'm the right person who should answer that question. ;) Regards, --F. On Mon, Jun 15, 2015 at 10:00:01AM +0200, Fritjof Bornebusch wrote: Hi, thanks for the hint. This one should do the trick. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.9 diff -u -p -r1.9 xmalloc.c --- xmalloc.c 13 Jun 2015 20:15:21 - 1.9 +++ xmalloc.c 15 Jun 2015 07:52:15 - @@ -68,13 +68,10 @@ xreallocarray(void *ptr, size_t nmemb, s char * xstrdup(const char *str) { - size_t len; char *cp; - - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + + if ((cp = strdup(str)) == NULL) + err(1, xstrdup); return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
On Wed, Jun 17, 2015 at 01:25:07PM +0200, Fritjof Bornebusch wrote: On Mon, Jun 15, 2015 at 10:22:27AM +0100, Nicholas Marriott wrote: What about diff and ssh and file? They all use the a copy of the same xmalloc.c. Personally, I would recommend that xstrdup just calls strdup(3), as Theo said: it's 100.00% portable. Right, that's fine, I meant are you going to change the others? But I don't think I'm the right person who should answer that question. ;) Regards, --F. On Mon, Jun 15, 2015 at 10:00:01AM +0200, Fritjof Bornebusch wrote: Hi, thanks for the hint. This one should do the trick. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.9 diff -u -p -r1.9 xmalloc.c --- xmalloc.c 13 Jun 2015 20:15:21 - 1.9 +++ xmalloc.c 15 Jun 2015 07:52:15 - @@ -68,13 +68,10 @@ xreallocarray(void *ptr, size_t nmemb, s char * xstrdup(const char *str) { - size_t len; char *cp; - - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + + if ((cp = strdup(str)) == NULL) + err(1, xstrdup); return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
What about diff and ssh and file? They all use the a copy of the same xmalloc.c. On Mon, Jun 15, 2015 at 10:00:01AM +0200, Fritjof Bornebusch wrote: Hi, thanks for the hint. This one should do the trick. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.9 diff -u -p -r1.9 xmalloc.c --- xmalloc.c 13 Jun 2015 20:15:21 - 1.9 +++ xmalloc.c 15 Jun 2015 07:52:15 - @@ -68,13 +68,10 @@ xreallocarray(void *ptr, size_t nmemb, s char * xstrdup(const char *str) { - size_t len; char *cp; - - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + + if ((cp = strdup(str)) == NULL) + err(1, xstrdup); return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
On Mon, Jun 15, 2015 at 10:09:39AM +0200, Fritjof Bornebusch wrote: On Sun, Jun 14, 2015 at 05:02:05PM -0600, Theo de Raadt wrote: But I am not sure about this change. xmalloc.c came from ssh (and is also used by file and diff). Would it be better to keep it in sync? How portable is strdup? strdup is extremely portable. The last mainstream operating system which lacked it was Ultrix. So you could call it 100.00% portable. Since there is no portable version of openRCS is it that necessary to focus on portability? Functions like explicit_bzero(3) are not portable either, but used widely. No but there is a portable version of ssh and it uses the same xmalloc.c Or is it more to find a balance between the usage of internal function, but make the tool not that hard to port to other systems? Regards, --F.
Re: [patch]rcs: xstrdup just wrappes strdup
Hi, thanks for the hint. This one should do the trick. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.9 diff -u -p -r1.9 xmalloc.c --- xmalloc.c 13 Jun 2015 20:15:21 - 1.9 +++ xmalloc.c 15 Jun 2015 07:52:15 - @@ -68,13 +68,10 @@ xreallocarray(void *ptr, size_t nmemb, s char * xstrdup(const char *str) { - size_t len; char *cp; - - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + + if ((cp = strdup(str)) == NULL) + err(1, xstrdup); return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
On Sun, Jun 14, 2015 at 05:02:05PM -0600, Theo de Raadt wrote: But I am not sure about this change. xmalloc.c came from ssh (and is also used by file and diff). Would it be better to keep it in sync? How portable is strdup? strdup is extremely portable. The last mainstream operating system which lacked it was Ultrix. So you could call it 100.00% portable. Since there is no portable version of openRCS is it that necessary to focus on portability? Functions like explicit_bzero(3) are not portable either, but used widely. Or is it more to find a balance between the usage of internal function, but make the tool not that hard to port to other systems? Regards, --F.
Re: [patch]rcs: xstrdup just wrappes strdup
On Wed, Jun 10, 2015 at 07:37:57PM +0200, Fritjof Bornebusch wrote: On Wed, May 20, 2015 at 10:55:34AM +0200, Fritjof Bornebusch wrote: On Tue, May 19, 2015 at 08:57:06PM +0200, Fritjof Bornebusch wrote: Hi, xstrdup just wrappes strdup, so there is no need to call xmalloc and strlcpy instead. Ping Without PGP stuff Use err() instead of errx(), so errno will be printed additionally. Thanks to Tim. Regards, --F. Regards, --F. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.8 diff -u -p -r1.8 xmalloc.c --- xmalloc.c 26 Mar 2015 15:17:30 - 1.8 +++ xmalloc.c 20 May 2015 08:53:01 - @@ -76,13 +76,11 @@ xfree(void *ptr) char * xstrdup(const char *str) { - size_t len; char *cp; - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + if ((cp = strdup(str)) == NULL) + err(1, xstrdup: copy string failed); + return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
But I am not sure about this change. xmalloc.c came from ssh (and is also used by file and diff). Would it be better to keep it in sync? How portable is strdup? strdup is extremely portable. The last mainstream operating system which lacked it was Ultrix. So you could call it 100.00% portable.
Re: [patch]rcs: xstrdup just wrappes strdup
Convention is usually to do err(1, strdup) with no additional text if using err rather than errx. But I am not sure about this change. xmalloc.c came from ssh (and is also used by file and diff). Would it be better to keep it in sync? How portable is strdup? On Sun, Jun 14, 2015 at 01:38:33PM +0200, Fritjof Bornebusch wrote: On Wed, Jun 10, 2015 at 07:37:57PM +0200, Fritjof Bornebusch wrote: On Wed, May 20, 2015 at 10:55:34AM +0200, Fritjof Bornebusch wrote: On Tue, May 19, 2015 at 08:57:06PM +0200, Fritjof Bornebusch wrote: Hi, xstrdup just wrappes strdup, so there is no need to call xmalloc and strlcpy instead. Ping Without PGP stuff Use err() instead of errx(), so errno will be printed additionally. Thanks to Tim. Regards, --F. Regards, --F. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.8 diff -u -p -r1.8 xmalloc.c --- xmalloc.c 26 Mar 2015 15:17:30 - 1.8 +++ xmalloc.c 20 May 2015 08:53:01 - @@ -76,13 +76,11 @@ xfree(void *ptr) char * xstrdup(const char *str) { - size_t len; char *cp; - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + if ((cp = strdup(str)) == NULL) + err(1, xstrdup: copy string failed); + return cp; }
Re: [patch]rcs: xstrdup just wrappes strdup
On Wed, May 20, 2015 at 10:55:34AM +0200, Fritjof Bornebusch wrote: On Tue, May 19, 2015 at 08:57:06PM +0200, Fritjof Bornebusch wrote: Hi, xstrdup just wrappes strdup, so there is no need to call xmalloc and strlcpy instead. Ping Use err() instead of errx(), so errno will be printed additionally. Thanks to Tim. Regards, --F. Regards, --F. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.8 diff -u -p -r1.8 xmalloc.c --- xmalloc.c 26 Mar 2015 15:17:30 - 1.8 +++ xmalloc.c 20 May 2015 08:53:01 - @@ -76,13 +76,11 @@ xfree(void *ptr) char * xstrdup(const char *str) { - size_t len; char *cp; - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + if ((cp = strdup(str)) == NULL) + err(1, xstrdup: copy string failed); + return cp; } pgp1q6Ck8BKwd.pgp Description: PGP signature
Re: [patch]rcs: xstrdup just wrappes strdup
On Tue, May 19, 2015 at 08:57:06PM +0200, Fritjof Bornebusch wrote: Hi, xstrdup just wrappes strdup, so there is no need to call xmalloc and strlcpy instead. Use err() instead of errx(), so errno will be printed additionally. Thanks to Tim. Regards, --F. Regards, --F. Index: xmalloc.c === RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v retrieving revision 1.8 diff -u -p -r1.8 xmalloc.c --- xmalloc.c 26 Mar 2015 15:17:30 - 1.8 +++ xmalloc.c 20 May 2015 08:53:01 - @@ -76,13 +76,11 @@ xfree(void *ptr) char * xstrdup(const char *str) { - size_t len; char *cp; - len = strlen(str) + 1; - cp = xmalloc(len); - if (strlcpy(cp, str, len) = len) - errx(1, xstrdup: string truncated); + if ((cp = strdup(str)) == NULL) + err(1, xstrdup: copy string failed); + return cp; } pgpW87xQmqoAq.pgp Description: PGP signature