Package: openglad Version: 0.98-3 Followup-For: Bug #463158 Here's a patch that fixes suspicious uses of "unsigned long" and several problems reported by valgrind. Now I can get the game to start and I was able to play for a few minutes. I still got a segfault somewhere in the second scenario but I don't want to hunt for it.
Richard Braakman
=== modified file 'src/game.cpp' --- src/game.cpp 2008-03-15 19:44:08 +0000 +++ src/game.cpp 2008-03-15 20:10:17 +0000 @@ -293,8 +293,8 @@ char temptext[10] = "GTL"; char savedgame[40]; char temp_version = 7; - unsigned long newcash; - unsigned long newscore = 0; + uint32_t newcash; + uint32_t newscore = 0; // short numguys; short listsize; short i; @@ -305,10 +305,10 @@ short temp_str, temp_dex, temp_con; short temp_short, temp_arm, temp_lev; char numplayers; - unsigned long temp_exp; + uint32_t temp_exp; short temp_kills; - long temp_level_kills; - long temp_td, temp_th, temp_ts; + int32_t temp_level_kills; + int32_t temp_td, temp_th, temp_ts; short temp_teamnum; // version 5+ short temp_allied; // v.7+ short temp_registered; // v.7+ @@ -547,8 +547,8 @@ char temptext[10] = "GTL"; char temp_version = 7; short next_scenario = (short) ( myscreen->scen_num + 1 ); - unsigned long newcash = myscreen->totalcash; - unsigned long newscore = myscreen->totalscore; + uint32_t newcash = myscreen->totalcash; + uint32_t newscore = myscreen->totalscore; // short numguys; short listsize; short i; @@ -558,7 +558,7 @@ short temp_str, temp_dex, temp_con; short temp_short, temp_arm, temp_lev; char numplayers = (char) myscreen->numviews; - unsigned long temp_exp; + uint32_t temp_exp; short temp_kills; long temp_level_kills; long temp_td, temp_th, temp_ts; === modified file 'src/glad.cpp' --- src/glad.cpp 2008-03-15 19:44:08 +0000 +++ src/glad.cpp 2008-03-15 20:25:20 +0000 @@ -63,7 +63,7 @@ char * filepath; filepath = get_file_path("openglad.cfg"); cfg.parse(filepath); - delete filepath; + free(filepath); cfg.commandline(argc, argv); create_dataopenglad(); === modified file 'src/loader.cpp' --- src/loader.cpp 2008-03-15 19:44:08 +0000 +++ src/loader.cpp 2008-03-15 22:14:35 +0000 @@ -293,10 +293,10 @@ { short i; - graphics = (unsigned char**) new short[SIZE_ORDERS*SIZE_FAMILIES*2]; + graphics = new unsigned char *[SIZE_ORDERS*SIZE_FAMILIES]; // hitpoints = new char[SIZE_ORDERS*SIZE_FAMILIES]; act_types = new char[SIZE_ORDERS*SIZE_FAMILIES]; - animations = (signed char***) new short[SIZE_ORDERS*SIZE_FAMILIES*2]; + animations = new signed char **[SIZE_ORDERS*SIZE_FAMILIES]; stepsizes = new long[SIZE_ORDERS*SIZE_FAMILIES]; lineofsight = new long[SIZE_ORDERS*SIZE_FAMILIES]; damage = new long[SIZE_ORDERS*SIZE_FAMILIES]; === modified file 'src/picker.cpp' --- src/picker.cpp 2008-03-15 19:44:08 +0000 +++ src/picker.cpp 2008-03-15 20:10:17 +0000 @@ -2379,8 +2379,8 @@ char temp_version = 7; unsigned char temp_playermode = playermode; long next_scenario = scen_level; - unsigned long newcash = money[0]; - unsigned long newscore = score[0]; + uint32_t newcash = money[0]; + uint32_t newscore = score[0]; // long numguys; long listsize; @@ -2576,8 +2576,8 @@ char savedgame[40]; char temp_version = 7; long next_scenario = 1; - unsigned long newcash = money[0]; - unsigned long newscore = 0; + uint32_t newcash = money[0]; + uint32_t newscore = 0; // long numguys; long listsize = 0; long i; @@ -2589,7 +2589,7 @@ long temp_str, temp_dex, temp_con; long temp_int, temp_arm, temp_lev; - unsigned long temp_exp; + uint32_t temp_exp; guy *tempguy; long temp_kills, temp_level_kills; long temp_td, temp_th, temp_ts; === modified file 'src/sai2x.cpp' --- src/sai2x.cpp 2008-03-15 19:44:08 +0000 +++ src/sai2x.cpp 2008-03-15 22:06:39 +0000 @@ -5,12 +5,12 @@ #define Log(x) fprintf(stderr,x) // Private var for SAI2x -static unsigned long colorMask = 0xF7DEF7DE; -static unsigned long lowPixelMask = 0x08210821; -static unsigned long qcolorMask = 0xE79CE79C; -static unsigned long qlowpixelMask = 0x18631863; -static unsigned long redblueMask = 0xF81F; -static unsigned long greenMask = 0x7E0; +static uint32_t colorMask = 0xF7DEF7DE; +static uint32_t lowPixelMask = 0x08210821; +static uint32_t qcolorMask = 0xE79CE79C; +static uint32_t qlowpixelMask = 0x18631863; +static uint32_t redblueMask = 0xF81F; +static uint32_t greenMask = 0x7E0; static int PixelsPerMask = 2; static int xsai_depth = 0; @@ -79,17 +79,17 @@ dst_pitch=dst_pitch/4; for (int y = 0; y < srch; y++) { - unsigned long* bP = (unsigned long*) srcPtr; - unsigned long* dP = (unsigned long*) dstPtr; + uint32_t* bP = (uint32_t*) srcPtr; + uint32_t* dP = (uint32_t*) dstPtr; for (int x = 0; x < srcw; x++) { - unsigned long color4, color5, color6; - unsigned long color1, color2, color3; - unsigned long colorA0, colorA1, colorA2, colorA3, + uint32_t color4, color5, color6; + uint32_t color1, color2, color3; + uint32_t colorA0, colorA1, colorA2, colorA3, colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; - unsigned long product1a, product1b, + uint32_t product1a, product1b, product2a, product2b; int add1, add2; @@ -256,6 +256,9 @@ unsigned char *srcPtr = src + (4*srcx + srcy*src_pitch); unsigned char *dstPtr = dst + (4*dstx + dsty*dst_pitch); + src_pitch=src_pitch/4; + dst_pitch=dst_pitch/4; + if (srcx + srcw >= src_pitch) { srcw = src_pitch - srcx; @@ -266,22 +269,19 @@ int xbeforelast1 = src_pitch - 1 - srcx; int xbeforelast2 = src_pitch - 2 - srcx; - src_pitch=src_pitch/4; - dst_pitch=dst_pitch/4; - for (int y = 0; y < srch; y++) { - unsigned long *bP = (unsigned long*) srcPtr; - unsigned long *dP = (unsigned long*) dstPtr; + uint32_t *bP = (uint32_t*) srcPtr; + uint32_t *dP = (uint32_t*) dstPtr; for (int x = 0; x < srcw; x++) { - unsigned long color4, color5, color6; - unsigned long color1, color2, color3; - unsigned long colorA0, colorA1, colorA2, colorA3, + uint32_t color4, color5, color6; + uint32_t color1, color2, color3; + uint32_t colorA0, colorA1, colorA2, colorA3, colorB0, colorB1, colorB2, colorB3, colorS1, colorS2; - unsigned long product1a, product1b, + uint32_t product1a, product1b, product2a, product2b; //--------------------------------------- B0 B1 B2 B3 @@ -490,7 +490,7 @@ unused=NULL; //for avoid warning //int j; unsigned int x, y; - unsigned long color[16]; + uint32_t color[16]; /* Point to the first 3 lines. */ src_line[0] = src; @@ -502,13 +502,13 @@ dst_line[1] = (unsigned char*) dest + dest_pitch; x = 0, y = 0; - unsigned long *lbp; - lbp = (unsigned long*)src_line[0]; + uint32_t *lbp; + lbp = (uint32_t*)src_line[0]; color[0] = *lbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0]; color[4] = color[0]; color[5] = color[0]; color[6] = *(lbp + 1); color[7] = *(lbp + 2); - lbp = (unsigned long*)src_line[2]; + lbp = (uint32_t*)src_line[2]; color[8] = *lbp; color[9] = color[8]; color[10] = *(lbp + 1); color[11] = *(lbp + 2); - lbp = (unsigned long*)src_line[3]; + lbp = (uint32_t*)src_line[3]; color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2); for (y = 0; y < height; y++) { @@ -516,7 +516,7 @@ /* Todo: x = width - 2, x = width - 1 */ for (x = 0; x < width; x++) { - unsigned long product1a, product1b, product2a, product2b; + uint32_t product1a, product1b, product2a, product2b; //--------------------------------------- B0 B1 B2 B3 0 1 2 3 // 4 5* 6 S2 -> 4 5* 6 7 @@ -580,10 +580,10 @@ else product1a = color[5]; - *((unsigned long *) (&dst_line[0][x * 8])) = product1a; - *((unsigned long *) (&dst_line[0][x * 8 + 4])) = product1b; - *((unsigned long *) (&dst_line[1][x * 8])) = product2a; - *((unsigned long *) (&dst_line[1][x * 8 + 4])) = product2b; + *((uint32_t *) (&dst_line[0][x * 8])) = product1a; + *((uint32_t *) (&dst_line[0][x * 8 + 4])) = product1b; + *((uint32_t *) (&dst_line[1][x * 8])) = product2a; + *((uint32_t *) (&dst_line[1][x * 8 + 4])) = product2b; /* Move color matrix forward */ color[0] = color[1]; color[4] = color[5]; color[8] = color[9]; color[12] = color[13]; @@ -592,10 +592,10 @@ if (x < width - 3) { x += 3; - color[3] = *(((unsigned long*)src_line[0]) + x); - color[7] = *(((unsigned long*)src_line[1]) + x); - color[11] = *(((unsigned long*)src_line[2]) + x); - color[15] = *(((unsigned long*)src_line[3]) + x); + color[3] = *(((uint32_t*)src_line[0]) + x); + color[7] = *(((uint32_t*)src_line[1]) + x); + color[11] = *(((uint32_t*)src_line[2]) + x); + color[15] = *(((uint32_t*)src_line[3]) + x); x -= 3; } } @@ -612,14 +612,14 @@ src_line[3] = src_line[2] + src_pitch; /* Then shift the color matrix up */ - unsigned long *lbp; - lbp = (unsigned long*)src_line[0]; + uint32_t *lbp; + lbp = (uint32_t*)src_line[0]; color[0] = *lbp; color[1] = color[0]; color[2] = *(lbp + 1); color[3] = *(lbp + 2); - lbp = (unsigned long*)src_line[1]; + lbp = (uint32_t*)src_line[1]; color[4] = *lbp; color[5] = color[4]; color[6] = *(lbp + 1); color[7] = *(lbp + 2); - lbp = (unsigned long*)src_line[2]; + lbp = (uint32_t*)src_line[2]; color[8] = *lbp; color[9] = color[9]; color[10] = *(lbp + 1); color[11] = *(lbp + 2); - lbp = (unsigned long*)src_line[3]; + lbp = (uint32_t*)src_line[3]; color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2); if (y < height - 1) { === modified file 'src/util.cpp' --- src/util.cpp 2008-03-15 19:44:08 +0000 +++ src/util.cpp 2008-03-15 22:03:04 +0000 @@ -101,7 +101,7 @@ if (filename && (infile = fopen(filename, attr))) { - delete filename; + free(filename); return infile; }