dungeon_crawler

diff prototype/psys/pattr.c @ 69:45172d087ebe

fixed some windows compatibility crap fixed a terrible stack overrun in psys (TODO: remember to fix in libpsys too)
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 07 Oct 2012 03:42:44 +0200
parents 2560a7ab0243
children
line diff
     1.1 --- a/prototype/psys/pattr.c	Sun Oct 07 02:05:11 2012 +0300
     1.2 +++ b/prototype/psys/pattr.c	Sun Oct 07 03:42:44 2012 +0200
     1.3 @@ -166,7 +166,7 @@
     1.4  	}
     1.5  
     1.6  	if(!(fp = fopen(fname, "r"))) {
     1.7 -		fprintf(stderr, "%s: failed to read file: %s: %s\n", __func__, fname, strerror(errno));
     1.8 +		fprintf(stderr, "%s: failed to read file: %s: %s\n", __FUNCTION__, fname, strerror(errno));
     1.9  		return -1;
    1.10  	}
    1.11  	res = psys_load_attr_stream(attr, fp);
    1.12 @@ -247,6 +247,9 @@
    1.13  	char *buf, *tmp;
    1.14  	struct cfgopt *opt;
    1.15  
    1.16 +	/* allocate a working buffer on the stack that could fit the current line */
    1.17 +	buf = alloca(strlen(line) + 1);
    1.18 +
    1.19  	line = stripspace((char*)line);
    1.20  	if(line[0] == '#' || !line[0]) {
    1.21  		return 0;	/* skip empty lines and comments */
    1.22 @@ -263,8 +266,6 @@
    1.23  	*opt->valstr++ = 0;
    1.24  	opt->valstr = stripspace(opt->valstr);
    1.25  
    1.26 -	/* allocate a working buffer on the stack that could fit the current line */
    1.27 -	buf = alloca(strlen(line) + 1);
    1.28  	strcpy(buf, line);
    1.29  	buf = stripspace(buf);
    1.30  
    1.31 @@ -274,7 +275,8 @@
    1.32  		float tval;
    1.33  
    1.34  		*tmp++ = 0;
    1.35 -		opt->name = strdup(buf);
    1.36 +		opt->name = malloc(strlen(buf) + 1);
    1.37 +		strcpy(opt->name, buf);
    1.38  
    1.39  		tval = strtod(tmp, &endp);
    1.40  		if(endp == tmp) { /* nada ... */
    1.41 @@ -285,7 +287,8 @@
    1.42  			opt->tm = (long)tval;
    1.43  		}
    1.44  	} else {
    1.45 -		opt->name = strdup(buf);
    1.46 +		opt->name = malloc(strlen(buf) + 1);
    1.47 +		strcpy(opt->name, buf);
    1.48  		opt->tm = 0;
    1.49  	}
    1.50  
    1.51 @@ -331,7 +334,9 @@
    1.52  {
    1.53  	if(opt) {
    1.54  		free(opt->name);
    1.55 +		opt->name = 0;
    1.56  	}
    1.57 +	opt = 0;
    1.58  }
    1.59  
    1.60  
    1.61 @@ -341,7 +346,7 @@
    1.62  	int res;
    1.63  
    1.64  	if(!(fp = fopen(fname, "w"))) {
    1.65 -		fprintf(stderr, "%s: failed to write file: %s: %s\n", __func__, fname, strerror(errno));
    1.66 +		fprintf(stderr, "%s: failed to write file: %s: %s\n", __FUNCTION__, fname, strerror(errno));
    1.67  		return -1;
    1.68  	}
    1.69  	res = psys_save_attr_stream(attr, fp);