[PATCH v2] html.c: Replace strdup() with xstrdup()

Lukas Fleischer cgit at cryptocrack.de
Sat Apr 6 12:50:11 CEST 2013


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




More information about the CGit mailing list