IMG_xpm.c
changeset 343 5bf0f0d6a74e
parent 339 2e4f9d95a8c8
child 344 d59179e84a3b
     1.1 --- a/IMG_xpm.c	Sun Jan 27 15:55:03 2013 -0800
     1.2 +++ b/IMG_xpm.c	Sun Feb 03 08:37:28 2013 -0800
     1.3 @@ -54,7 +54,7 @@
     1.4  /* See if an image is contained in a data source */
     1.5  int IMG_isXPM(SDL_RWops *src)
     1.6  {
     1.7 -	int start;
     1.8 +	Sint64 start;
     1.9  	int is_XPM;
    1.10  	char magic[9];
    1.11  
    1.12 @@ -63,7 +63,7 @@
    1.13  	start = SDL_RWtell(src);
    1.14  	is_XPM = 0;
    1.15  	if ( SDL_RWread(src, magic, sizeof(magic), 1) ) {
    1.16 -		if ( memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) {
    1.17 +		if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) {
    1.18  			is_XPM = 1;
    1.19  		}
    1.20  	}
    1.21 @@ -106,7 +106,7 @@
    1.22  
    1.23  	/* we know how many entries we need, so we can allocate
    1.24  	   everything here */
    1.25 -	hash = malloc(sizeof *hash);
    1.26 +	hash = (struct color_hash *)SDL_malloc(sizeof *hash);
    1.27  	if(!hash)
    1.28  		return NULL;
    1.29  
    1.30 @@ -117,13 +117,13 @@
    1.31  	hash->maxnum = maxnum;
    1.32  	bytes = hash->size * sizeof(struct hash_entry **);
    1.33  	hash->entries = NULL;	/* in case malloc fails */
    1.34 -	hash->table = malloc(bytes);
    1.35 +	hash->table = (struct hash_entry **)SDL_malloc(bytes);
    1.36  	if(!hash->table)
    1.37  		return NULL;
    1.38  	memset(hash->table, 0, bytes);
    1.39 -	hash->entries = malloc(maxnum * sizeof(struct hash_entry));
    1.40 +	hash->entries = (struct hash_entry *)SDL_malloc(maxnum * sizeof(struct hash_entry));
    1.41  	if(!hash->entries) {
    1.42 -		free(hash->table);
    1.43 +		SDL_free(hash->table);
    1.44  		return NULL;
    1.45  	}
    1.46  	hash->next_free = hash->entries;
    1.47 @@ -149,7 +149,7 @@
    1.48  {
    1.49  	struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)];
    1.50  	while(entry) {
    1.51 -		if(memcmp(key, entry->key, cpp) == 0)
    1.52 +		if(SDL_memcmp(key, entry->key, cpp) == 0)
    1.53  			return entry->color;
    1.54  		entry = entry->next;
    1.55  	}
    1.56 @@ -158,10 +158,12 @@
    1.57  
    1.58  static void free_colorhash(struct color_hash *hash)
    1.59  {
    1.60 -	if(hash && hash->table) {
    1.61 -		free(hash->table);
    1.62 -		free(hash->entries);
    1.63 -		free(hash);
    1.64 +	if(hash) {
    1.65 +		if(hash->table)
    1.66 +			SDL_free(hash->table);
    1.67 +		if(hash->entries)
    1.68 +			SDL_free(hash->entries);
    1.69 +		SDL_free(hash);
    1.70  	}
    1.71  }
    1.72  
    1.73 @@ -871,7 +873,7 @@
    1.74  			buf[4] = buf[5] = spec[3];
    1.75  			break;
    1.76  		case 7:
    1.77 -			memcpy(buf, spec + 1, 6);
    1.78 +			SDL_memcpy(buf, spec + 1, 6);
    1.79  			break;
    1.80  		case 13:
    1.81  			buf[0] = spec[1];
    1.82 @@ -928,9 +930,9 @@
    1.83  			len += 4;	/* "\",\n\0" */
    1.84  			if(len > buflen){
    1.85  				buflen = len;
    1.86 -				linebufnew = realloc(linebuf, buflen);
    1.87 +				linebufnew = (char *)SDL_realloc(linebuf, buflen);
    1.88  				if(!linebufnew) {
    1.89 -					free(linebuf);
    1.90 +					SDL_free(linebuf);
    1.91  					error = "Out of memory";
    1.92  					return NULL;
    1.93  				}
    1.94 @@ -948,9 +950,9 @@
    1.95  					if(buflen == 0)
    1.96  						buflen = 16;
    1.97  					buflen *= 2;
    1.98 -					linebufnew = realloc(linebuf, buflen);
    1.99 +					linebufnew = (char *)SDL_realloc(linebuf, buflen);
   1.100  					if(!linebufnew) {
   1.101 -						free(linebuf);
   1.102 +						SDL_free(linebuf);
   1.103  						error = "Out of memory";
   1.104  						return NULL;
   1.105  					}
   1.106 @@ -970,20 +972,20 @@
   1.107  
   1.108  #define SKIPSPACE(p)				\
   1.109  do {						\
   1.110 -	while(isspace((unsigned char)*(p)))	\
   1.111 +	while(SDL_isspace((unsigned char)*(p)))	\
   1.112  	      ++(p);				\
   1.113  } while(0)
   1.114  
   1.115  #define SKIPNONSPACE(p)					\
   1.116  do {							\
   1.117 -	while(!isspace((unsigned char)*(p)) && *p)	\
   1.118 +	while(!SDL_isspace((unsigned char)*(p)) && *p)	\
   1.119  	      ++(p);					\
   1.120  } while(0)
   1.121  
   1.122  /* read XPM from either array or RWops */
   1.123  static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src)
   1.124  {
   1.125 -	int start = 0;
   1.126 +	Sint64 start = 0;
   1.127  	SDL_Surface *image = NULL;
   1.128  	int index;
   1.129  	int x, y;
   1.130 @@ -1019,13 +1021,13 @@
   1.131  	 * Right now we don't use the hotspots but it should be handled
   1.132  	 * one day.
   1.133  	 */
   1.134 -	if(sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4
   1.135 +	if(SDL_sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4
   1.136  	   || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) {
   1.137  		error = "Invalid format description";
   1.138  		goto done;
   1.139  	}
   1.140  
   1.141 -	keystrings = malloc(ncolors * cpp);
   1.142 +	keystrings = (char *)SDL_malloc(ncolors * cpp);
   1.143  	if(!keystrings) {
   1.144  		error = "Out of memory";
   1.145  		goto done;
   1.146 @@ -1085,7 +1087,7 @@
   1.147  			if(!color_to_rgb(colname, p - colname, &rgb))
   1.148  				continue;
   1.149  
   1.150 -			memcpy(nextkey, line, cpp);
   1.151 +			SDL_memcpy(nextkey, line, cpp);
   1.152  			if(indexed) {
   1.153  				SDL_Color *c = im_colors + index;
   1.154  				c->r = (Uint8)(rgb >> 16);
   1.155 @@ -1104,7 +1106,7 @@
   1.156  
   1.157  	/* Read the pixels */
   1.158  	pixels_len = w * cpp;
   1.159 -	dst = image->pixels;
   1.160 +	dst = (Uint8 *)image->pixels;
   1.161  	for(y = 0; y < h; y++) {
   1.162  		line = get_next_line(xpmlines, src, pixels_len);
   1.163  		if(indexed) {
   1.164 @@ -1137,9 +1139,11 @@
   1.165  		}
   1.166  		IMG_SetError(error);
   1.167  	}
   1.168 -	free(keystrings);
   1.169 +	if (keystrings)
   1.170 +		SDL_free(keystrings);
   1.171  	free_colorhash(colors);
   1.172 -	free(linebuf);
   1.173 +	if (linebuf)
   1.174 +		SDL_free(linebuf);
   1.175  	return(image);
   1.176  }
   1.177