comparison src/nsterm.m @ 99904:ba4876d944bc

Fix bug #1362. * image.c (x_clear_image_1): Do not free background under HAVE_NS, it is not an indexed color. * nsterm.m (free_indexed_color): Add argument checking. * nsfns.m: Move config.h to before system includes (advised by Dan N.).
author Adrian Robert <Adrian.B.Robert@gmail.com>
date Tue, 25 Nov 2008 02:45:39 +0000
parents de06f7b71b82
children d7ec854f5dc4
comparison
equal deleted inserted replaced
99903:8fb8b5898508 99904:ba4876d944bc
23 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com) 23 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
24 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net) 24 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
25 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu) 25 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
26 */ 26 */
27 27
28 /* This should be the first include, as it may set up #defines affecting
29 interpretation of even the system includes. */
30 #include "config.h"
31
28 #include <math.h> 32 #include <math.h>
29 #include <sys/types.h> 33 #include <sys/types.h>
30 #include <time.h> 34 #include <time.h>
31 #include <unistd.h> 35 #include <unistd.h>
32 36
33 #include "config.h"
34 #include "lisp.h" 37 #include "lisp.h"
35 #include "blockinput.h" 38 #include "blockinput.h"
36 #include "sysselect.h" 39 #include "sysselect.h"
37 #include "nsterm.h" 40 #include "nsterm.h"
38 #include "systime.h" 41 #include "systime.h"
1278 color_table->colors 1281 color_table->colors
1279 = (NSColor **)xrealloc (color_table->colors, 1282 = (NSColor **)xrealloc (color_table->colors,
1280 color_table->size * sizeof (NSColor *)); 1283 color_table->size * sizeof (NSColor *));
1281 } 1284 }
1282 idx = color_table->avail++; 1285 idx = color_table->avail++;
1283 index = [NSNumber numberWithUnsignedInt: idx];
1284 } 1286 }
1285 1287
1286 color_table->colors[idx] = color; 1288 color_table->colors[idx] = color;
1287 [color retain]; 1289 [color retain];
1288 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/ 1290 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1291 1293
1292 1294
1293 void 1295 void
1294 ns_free_indexed_color (unsigned long idx, struct frame *f) 1296 ns_free_indexed_color (unsigned long idx, struct frame *f)
1295 { 1297 {
1296 struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; 1298 struct ns_color_table *color_table;
1297 NSColor *color; 1299 NSColor *color;
1298 if (!idx) 1300 NSNumber *index;
1301
1302 if (!f)
1299 return; 1303 return;
1304
1305 color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
1306
1307 if (idx <= 0 || idx >= color_table->size) {
1308 message1("ns_free_indexed_color: Color index out of range.\n");
1309 return;
1310 }
1311
1312 index = [NSNumber numberWithUnsignedInt: idx];
1313 if ([color_table->empty_indices containsObject: index]) {
1314 message1("ns_free_indexed_color: attempt to free already freed color.\n");
1315 return;
1316 }
1317
1300 color = color_table->colors[idx]; 1318 color = color_table->colors[idx];
1301 [color release]; 1319 [color release];
1302 color_table->colors[idx] = nil; 1320 color_table->colors[idx] = nil;
1303 [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]]; 1321 [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]];
1304 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/ 1322 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/