* [PATCH] html.c: Replace strdup() with xstrdup()
@ 2013-04-06 9:11 cgit
2013-04-06 9:17 ` [PATCH v2] " cgit
2013-04-06 11:30 ` [PATCH v3] " cgit
0 siblings, 2 replies; 7+ messages in thread
From: cgit @ 2013-04-06 9:11 UTC (permalink / raw)
Use the xstrdup() wrapper which already bails out if strdup() returns a
NULL pointer.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
`grep '[^x]strdup' *.c` tells me that this is the only place where we
still use strdup() instead of xstrdup().
html.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/html.c b/html.c
index d60a41f..88f3e67 100644
--- a/html.c
+++ b/html.c
@@ -306,11 +306,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
if (!txt_)
return 0;
- o = t = txt = strdup(txt_);
- if (t == NULL) {
- printf("Out of memory\n");
- exit(1);
- }
+ o = t = txt = xstrdup(txt_);
while ((c=*t) != '\0') {
if (c == '=') {
*t = '\0';
--
1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] html.c: Replace strdup() with xstrdup()
2013-04-06 9:11 [PATCH] html.c: Replace strdup() with xstrdup() cgit
@ 2013-04-06 9:17 ` cgit
2013-04-06 9:44 ` john
2013-04-06 11:30 ` [PATCH v3] " cgit
1 sibling, 1 reply; 7+ messages in thread
From: cgit @ 2013-04-06 9:17 UTC (permalink / raw)
Use the xstrdup() wrapper which already bails out if strdup() returns a
NULL pointer.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
Forgot to add the git-compat-util header.
html.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/html.c b/html.c
index d60a41f..705b710 100644
--- a/html.c
+++ b/html.c
@@ -12,6 +12,7 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
+#include <git-compat-util.h>
/* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
static const char* url_escape_table[256] = {
@@ -306,11 +307,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
if (!txt_)
return 0;
- o = t = txt = strdup(txt_);
- if (t == NULL) {
- printf("Out of memory\n");
- exit(1);
- }
+ o = t = txt = xstrdup(txt_);
while ((c=*t) != '\0') {
if (c == '=') {
*t = '\0';
--
1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] html.c: Replace strdup() with xstrdup()
2013-04-06 9:17 ` [PATCH v2] " cgit
@ 2013-04-06 9:44 ` john
2013-04-06 10:50 ` cgit
0 siblings, 1 reply; 7+ messages in thread
From: john @ 2013-04-06 9:44 UTC (permalink / raw)
On Sat, Apr 06, 2013 at 11:17:12AM +0200, Lukas Fleischer wrote:
> Use the xstrdup() wrapper which already bails out if strdup() returns a
> NULL pointer.
>
> Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
> ---
> Forgot to add the git-compat-util header.
>
> html.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/html.c b/html.c
> index d60a41f..705b710 100644
> --- a/html.c
> +++ b/html.c
> @@ -12,6 +12,7 @@
> #include <stdarg.h>
> #include <string.h>
> #include <errno.h>
> +#include <git-compat-util.h>
git-compat-util.h should be included before any other headers, since it
may #define variables that affect how those headers behave.
> /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
> static const char* url_escape_table[256] = {
> @@ -306,11 +307,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
> if (!txt_)
> return 0;
>
> - o = t = txt = strdup(txt_);
> - if (t == NULL) {
> - printf("Out of memory\n");
> - exit(1);
> - }
> + o = t = txt = xstrdup(txt_);
> while ((c=*t) != '\0') {
> if (c == '=') {
> *t = '\0';
> --
> 1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] html.c: Replace strdup() with xstrdup()
2013-04-06 9:44 ` john
@ 2013-04-06 10:50 ` cgit
2013-04-06 11:14 ` john
0 siblings, 1 reply; 7+ messages in thread
From: cgit @ 2013-04-06 10:50 UTC (permalink / raw)
On Sat, Apr 06, 2013 at 10:44:10AM +0100, John Keeping wrote:
> On Sat, Apr 06, 2013 at 11:17:12AM +0200, Lukas Fleischer wrote:
> > Use the xstrdup() wrapper which already bails out if strdup() returns a
> > NULL pointer.
> >
> > Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
> > ---
> > Forgot to add the git-compat-util header.
> >
> > html.c | 7 ++-----
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> >
> > diff --git a/html.c b/html.c
> > index d60a41f..705b710 100644
> > --- a/html.c
> > +++ b/html.c
> > @@ -12,6 +12,7 @@
> > #include <stdarg.h>
> > #include <string.h>
> > #include <errno.h>
> > +#include <git-compat-util.h>
>
> git-compat-util.h should be included before any other headers, since it
> may #define variables that affect how those headers behave.
Good catch. On second thought, shouldn't we rather include "cgit.h" like
it is done in all other source files?
>
> > /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
> > static const char* url_escape_table[256] = {
> > @@ -306,11 +307,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
> > if (!txt_)
> > return 0;
> >
> > - o = t = txt = strdup(txt_);
> > - if (t == NULL) {
> > - printf("Out of memory\n");
> > - exit(1);
> > - }
> > + o = t = txt = xstrdup(txt_);
> > while ((c=*t) != '\0') {
> > if (c == '=') {
> > *t = '\0';
> > --
> > 1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] html.c: Replace strdup() with xstrdup()
2013-04-06 10:50 ` cgit
@ 2013-04-06 11:14 ` john
0 siblings, 0 replies; 7+ messages in thread
From: john @ 2013-04-06 11:14 UTC (permalink / raw)
On Sat, Apr 06, 2013 at 12:50:11PM +0200, Lukas Fleischer wrote:
> On Sat, Apr 06, 2013 at 10:44:10AM +0100, John Keeping wrote:
> > On Sat, Apr 06, 2013 at 11:17:12AM +0200, Lukas Fleischer wrote:
> > > Use the xstrdup() wrapper which already bails out if strdup() returns a
> > > NULL pointer.
> > >
> > > Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
> > > ---
> > > Forgot to add the git-compat-util header.
> > >
> > > html.c | 7 ++-----
> > > 1 file changed, 2 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/html.c b/html.c
> > > index d60a41f..705b710 100644
> > > --- a/html.c
> > > +++ b/html.c
> > > @@ -12,6 +12,7 @@
> > > #include <stdarg.h>
> > > #include <string.h>
> > > #include <errno.h>
> > > +#include <git-compat-util.h>
> >
> > git-compat-util.h should be included before any other headers, since it
> > may #define variables that affect how those headers behave.
>
> Good catch. On second thought, shouldn't we rather include "cgit.h" like
> it is done in all other source files?
Yes, that's probably better.
> >
> > > /* Percent-encoding of each character, except: a-zA-Z0-9!$()*,./:;@- */
> > > static const char* url_escape_table[256] = {
> > > @@ -306,11 +307,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
> > > if (!txt_)
> > > return 0;
> > >
> > > - o = t = txt = strdup(txt_);
> > > - if (t == NULL) {
> > > - printf("Out of memory\n");
> > > - exit(1);
> > > - }
> > > + o = t = txt = xstrdup(txt_);
> > > while ((c=*t) != '\0') {
> > > if (c == '=') {
> > > *t = '\0';
> > > --
> > > 1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] html.c: Replace strdup() with xstrdup()
2013-04-06 9:11 [PATCH] html.c: Replace strdup() with xstrdup() cgit
2013-04-06 9:17 ` [PATCH v2] " cgit
@ 2013-04-06 11:30 ` cgit
2013-04-06 14:26 ` Jason
1 sibling, 1 reply; 7+ messages in thread
From: cgit @ 2013-04-06 11:30 UTC (permalink / raw)
Use the xstrdup() wrapper which already bails out if strdup() returns a
NULL pointer.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
Note that this revision is based on John's patch ("Always #include
corresponding .h in .c files") which gets a +1 from me.
html.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/html.c b/html.c
index 1104f97..8c45ba6 100644
--- a/html.c
+++ b/html.c
@@ -6,6 +6,7 @@
* (see COPYING for full license text)
*/
+#include "cgit.h"
#include "html.h"
#include <unistd.h>
#include <stdio.h>
@@ -307,11 +308,7 @@ int http_parse_querystring(const char *txt_, void (*fn)(const char *name, const
if (!txt_)
return 0;
- o = t = txt = strdup(txt_);
- if (t == NULL) {
- printf("Out of memory\n");
- exit(1);
- }
+ o = t = txt = xstrdup(txt_);
while ((c=*t) != '\0') {
if (c == '=') {
*t = '\0';
--
1.8.2.674.g2c8b7bf
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] html.c: Replace strdup() with xstrdup()
2013-04-06 11:30 ` [PATCH v3] " cgit
@ 2013-04-06 14:26 ` Jason
0 siblings, 0 replies; 7+ messages in thread
From: Jason @ 2013-04-06 14:26 UTC (permalink / raw)
Nice find. Merged to wip.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-04-06 14:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-06 9:11 [PATCH] html.c: Replace strdup() with xstrdup() cgit
2013-04-06 9:17 ` [PATCH v2] " cgit
2013-04-06 9:44 ` john
2013-04-06 10:50 ` cgit
2013-04-06 11:14 ` john
2013-04-06 11:30 ` [PATCH v3] " cgit
2013-04-06 14:26 ` Jason
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).