Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit fe19c0f

Browse files
mwiederricochet1k
authored andcommitted
fixed MCPath alloc, eliminated more compiler warnings
1 parent 8c899ad commit fe19c0f

8 files changed

Lines changed: 76 additions & 31 deletions

File tree

engine/src/eventqueue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ extern Boolean tripleclick;
3737

3838
////////////////////////////////////////////////////////////////////////////////
3939

40-
static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p_id, uint32_t p_taps, int32_t x, int32_t y);
40+
// MDW 2013-04-16: handle_touch is declared but not defined
41+
// static void handle_touch(MCStack *p_stack, MCEventTouchPhase p_phase, uint32_t p_id, uint32_t p_taps, int32_t x, int32_t y);
4142

4243
enum MCEventType
4344
{

engine/src/lnxmplayer.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ bool MPlayer::launch_player(void)
186186

187187

188188
char t_widbuf[20];
189-
sprintf(t_widbuf, "%d", m_window);
189+
// MDW-2013-04-16: m_window is an XID so needs "%ld"
190+
sprintf(t_widbuf, "%ld", m_window);
190191

191192
// TS-2007-12-17 : Added in the ability to drop down to use the native X11 video driver if Xv is not present (i.e. no hardware
192193
// video support.
@@ -373,7 +374,8 @@ void MPlayer::play ( bool p_play )
373374
{
374375
if ( m_playing != p_play )
375376
{
376-
write_command("pause");
377+
// MDW-2013-04-16: avoiding compiler warning by casting char *
378+
write_command(const_cast<char *>("pause"));
377379
m_playing = !m_playing ;
378380
}
379381
}
@@ -410,7 +412,8 @@ void MPlayer::seek ( int4 p_amount )
410412

411413
void MPlayer::seek(void)
412414
{
413-
write_command("frame_step");
415+
// MDW-2013-04-16: avoiding compiler warning by casting char *
416+
write_command(const_cast<char *>("frame_step"));
414417
}
415418

416419
void MPlayer::osd ( uint4 p_level = 0 )
@@ -422,15 +425,17 @@ void MPlayer::osd ( uint4 p_level = 0 )
422425

423426
void MPlayer::osd(void)
424427
{
425-
write_command("pausing_keep osd");
428+
// MDW-2013-04-16: avoiding compiler warning by casting char *
429+
write_command(const_cast<char *>("pausing_keep osd"));
426430
}
427431

428432
void MPlayer::quit(void)
429433
{
430434
if ( m_cpid > -1 && m_window != DNULL )
431435
{
432436
int t_status ;
433-
write_command("quit");
437+
// MDW-2013-04-16: avoiding compiler warning by casting char *
438+
write_command(const_cast<char *>("quit"));
434439
// Wait for the child to quit.
435440
waitpid(m_cpid, &t_status, 0) ;
436441
shutdown();
@@ -457,7 +462,8 @@ void MPlayer::set_property ( char * p_prop, char * p_value )
457462
char * MPlayer::get_property ( char * p_prop )
458463
{
459464
if ( m_window == DNULL )
460-
return "-1";
465+
// MDW-2013-04-16: avoiding compiler warning by casting char *
466+
return const_cast<char *>("-1");
461467

462468
char t_response[1024] ;
463469
char t_question[1024];
@@ -473,7 +479,8 @@ uint4 MPlayer::getduration(void)
473479
if ( m_duration == -1 )
474480
{
475481
char * t_ret ;
476-
t_ret = get_property("stream_length") ;
482+
// MDW-2013-04-16: avoiding compiler warning by casting char *
483+
t_ret = get_property(const_cast<char *>("stream_length")) ;
477484
if ( t_ret != NULL )
478485
m_duration = atoi(t_ret);
479486
else
@@ -486,7 +493,8 @@ uint4 MPlayer::getduration(void)
486493
uint4 MPlayer::getcurrenttime(void)
487494
{
488495
char * t_ret ;
489-
t_ret = get_property("stream_pos") ;
496+
// MDW-2013-04-16: avoiding compiler warning by casting char *
497+
t_ret = get_property(const_cast<char *>("stream_pos")) ;
490498
if ( t_ret != NULL )
491499
return atoi(t_ret);
492500
else
@@ -501,7 +509,8 @@ uint4 MPlayer::gettimescale(void)
501509
{
502510
double t_length ;
503511
char * t_ret ;
504-
t_ret = get_property("length") ;
512+
// MDW-2013-04-16: avoiding compiler warning by casting char *
513+
t_ret = get_property(const_cast<char *>("length")) ;
505514
if ( t_ret != NULL )
506515
{
507516
t_length = atof(t_ret);
@@ -518,27 +527,31 @@ void MPlayer::setspeed(double p_speed)
518527
{
519528
char t_buffer[100];
520529
sprintf(t_buffer, "%f", p_speed);
521-
set_property("speed", t_buffer);
530+
// MDW-2013-04-16: avoiding compiler warning by casting char *
531+
set_property(const_cast<char *>("speed"), t_buffer);
522532
}
523533

524534
void MPlayer::setlooping(bool p_loop)
525535
{
526-
set_property("looping", (char*)(p_loop ? "0" : "-1") ) ;
536+
// MDW-2013-04-16: avoiding compiler warning by casting char *
537+
set_property(const_cast<char *>("looping"), (char*)(p_loop ? "0" : "-1") ) ;
527538
}
528539

529540
void MPlayer::setloudness(uint4 p_volume )
530541
{
531542
char t_buffer[4] ;
532543
sprintf(t_buffer,"%d", p_volume);
533-
set_property("volume", t_buffer);
544+
// MDW-2013-04-16: avoiding compiler warning by casting char *
545+
set_property(const_cast<char *>("volume"), t_buffer);
534546
}
535547

536548
uint4 MPlayer::getloudness(void)
537549
{
538550
if ( m_loudness == -1 )
539551
{
540552
char * t_ret ;
541-
t_ret = get_property("volume") ;
553+
// MDW-2013-04-16: avoiding compiler warning by casting char *
554+
t_ret = get_property(const_cast<char *>("volume")) ;
542555
if ( t_ret != NULL)
543556
m_loudness = atoi(t_ret);
544557
else

engine/src/lnxmplayer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ class MPlayer
6969
int m_pfd_read[2];
7070
pid_t m_cpid;
7171

72-
uint4 m_duration ;
73-
uint4 m_timescale ;
74-
uint4 m_loudness ;
72+
// MDW-2013-04-16: lnxmplayer.cpp sets these to -1 and compares for -1
73+
// so changed from uint4 to int4
74+
int4 m_duration ;
75+
int4 m_timescale ;
76+
int4 m_loudness ;
7577

7678

7779
bool launch_player(void) ;

engine/src/lnxpsprinter.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ bool MCPSPrinter::DoReset(const char *p_name)
641641
m_printersettings . printername = strdup(p_name);
642642

643643
FlushSettings();
644+
// MDW 2013-04-16: DoReset needs to return a bool
645+
return (true);
644646
}
645647

646648

@@ -1369,7 +1371,8 @@ void MCPSMetaContext::printimage(MCBitmap *image, int2 dx, int2 dy, real8 xscale
13691371
}
13701372
else
13711373
{
1372-
if (c.red + c.green + c.blue > MAXUINT2 * 3 / 2)
1374+
// MDW 2013-04-16: need to compare unsigned with unsigned
1375+
if ((unsigned)(c.red + c.green + c.blue) > (unsigned)(MAXUINT2 * 3 / 2))
13731376
PSwrite("F");
13741377
else
13751378
PSwrite("0");
@@ -1473,7 +1476,8 @@ void MCPSMetaContext::printpattern(MCBitmap *image)
14731476
}
14741477
else
14751478
{
1476-
if (c.red + c.green + c.blue > MAXUINT2 * 3 / 2)
1479+
// MDW 2013-04-16: need to compare unsigned with unsigned
1480+
if ((unsigned)(c.red + c.green + c.blue) > (unsigned)(MAXUINT2 * 3 / 2))
14771481
PSwrite("F");
14781482
else
14791483
PSwrite("0");
@@ -1511,8 +1515,8 @@ void MCPSMetaContext::fillpattern ( Pixmap p_pattern, MCPoint p_origin )
15111515
{
15121516
if ( !pattern_created ( p_pattern ) )
15131517
create_pattern ( p_pattern ) ;
1514-
1515-
sprintf(buffer, "pattern_id_%d\n", p_pattern );
1518+
// MDW 2013-04-16: p_pattern is an XID (long unsigned int), so need $ld here
1519+
sprintf(buffer, "pattern_id_%ld\n", p_pattern );
15161520
PSwrite ( buffer );
15171521
sprintf(buffer, "[1 0 0 1 %d %d]\n", p_origin.x, cardheight - p_origin.y);
15181522
PSwrite(buffer);
@@ -1529,7 +1533,8 @@ void MCPSMetaContext::create_pattern ( Pixmap p_pattern )
15291533
MCBitmap *image ;
15301534
image = MCscreen -> getimage ( p_pattern, 0, 0, t_w, t_h, false ) ;
15311535

1532-
sprintf(buffer, "/pattern_id_%d\n", p_pattern);
1536+
// MDW 2013-04-16: p_pattern is an XID (long unsigned int), so need $ld here
1537+
sprintf(buffer, "/pattern_id_%ld\n", p_pattern);
15331538
PSwrite ( buffer ) ;
15341539

15351540
PSwrite("<<\n");

engine/src/path.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,15 @@ void MCPath::release(void)
149149

150150
f_references -= 1;
151151
if (f_references == 0)
152+
{
153+
// MDW-2013-04-17: data storage is now separate from MCPath object
154+
// so don't forget to free it as well.
155+
if (this -> f_commands != NULL)
156+
free(this -> f_commands);
157+
if (this -> f_data != NULL)
158+
free(this -> f_data);
152159
free(this);
160+
}
153161
}
154162

155163
void MCPath::retain(void)
@@ -163,10 +171,15 @@ void MCPath::retain(void)
163171
MCPath *MCPath::allocate(uint4 p_command_count, uint4 p_point_count)
164172
{
165173
MCPath *t_path;
166-
t_path = (MCPath *)malloc(12 + ((p_command_count + 4) & ~3) + p_point_count * 8);
174+
175+
// MDW-2013-04-17: eliminating magic numbers, adjusting for 64-bit space
176+
t_path = new MCPath;
167177
t_path -> f_references = 1;
168-
t_path -> f_commands = (uint1 *)t_path + 12;
169-
t_path -> f_data = (int4 *)t_path + 3 + (((p_command_count + 4) & ~3) / 4);
178+
179+
// pointer to a single byte that contains the commands
180+
t_path -> f_commands = (uint1*)malloc(sizeof(int));
181+
// point to the data space: each point is two ints
182+
t_path -> f_data = (int4*)malloc(p_point_count * 2 * sizeof(int));
170183
return t_path;
171184
}
172185

engine/src/redraw.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,10 @@ void MCStack::setacceleratedrendering(bool p_value)
10821082
return;
10831083

10841084
// Otherwise, we configure based on platform settings.
1085-
int32_t t_tile_size;
1086-
int32_t t_cache_limit;
1085+
// MDW 2013-04-16: failsafe initializing values
1086+
// MDW-2013-04-16: these are now unsigned
1087+
uint32_t t_tile_size = 32;
1088+
uint32_t t_cache_limit = 32 * 1024 * 1024;
10871089
MCTileCacheCompositorType t_compositor_type;
10881090
#ifdef _MAC_DESKTOP
10891091
t_compositor_type = kMCTileCacheCompositorCoreGraphics;
@@ -1112,6 +1114,11 @@ void MCStack::setacceleratedrendering(bool p_value)
11121114
t_tile_size = 64, t_cache_limit = 32 * 1024 * 1024;
11131115
else
11141116
t_tile_size = 64, t_cache_limit = 64 * 1024 * 1024;
1117+
#else
1118+
// MDW 2013-04-16: need an else clause here
1119+
t_tile_size = 32;
1120+
t_cache_limit = 32 * 1024 * 1024;
1121+
t_compositor_type = kMCTileCacheCompositorStaticOpenGL;
11151122
#endif
11161123

11171124
MCTileCacheCreate(t_tile_size, t_cache_limit, m_tilecache);

engine/src/srvoutput.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ static void MCServerOutputUnicodeChars(const unichar_t *p_chars, uint32_t p_char
306306
while(t_index < p_char_count)
307307
{
308308
if (p_chars[t_index] == 10 ||
309-
p_chars[t_index] < 128 && (t_index == p_char_count - 1 || p_chars[t_index + 1] < 128))
309+
(p_chars[t_index] < 128 && (t_index == p_char_count - 1 || p_chars[t_index + 1] < 128))
310+
)
310311
{
311312
if (p_chars[t_index] != 10)
312313
t_output[t_output_count++] = (char)p_chars[t_index];
@@ -360,7 +361,8 @@ static void MCServerOutputUnicodeMarkup(const unichar_t *p_chars, uint32_t p_cha
360361
{
361362
if (p_chars[t_index] == 10 ||
362363
(p_is_content && (p_chars[t_index] == '&' || p_chars[t_index] == '<' || p_chars[t_index] == '>' || p_chars[t_index] == '"')) ||
363-
p_chars[t_index] < 128 && (t_index == p_char_count - 1 || p_chars[t_index + 1] < 128))
364+
(p_chars[t_index] < 128 && (t_index == p_char_count - 1 || p_chars[t_index + 1] < 128))
365+
)
364366
{
365367
MCServerOutputMarkupChar((char)p_chars[t_index], p_is_content, t_output, t_output_count);
366368
t_index += 1;

engine/src/tilecache.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ struct MCTileCache
136136
bool clean : 1;
137137

138138
// The size of a single tile in pixels (tiles are square).
139-
int32_t tile_size;
139+
// MDW 2013-04-16: no need for this to be a signed int, messed up comparisons
140+
uint32_t tile_size;
140141

141142
// The number of bytes currently in use by cached images.
142143
uint32_t cache_size;
@@ -1041,7 +1042,8 @@ static void MCTileCacheFlushCellsContainingLayers(MCTileCacheRef self, uint32_t
10411042
t_cell = MCTileCacheGetSceneryCell(self, x, y);
10421043

10431044
// Loop through each tile, destroying any that have become invalid.
1044-
int32_t t_new_tile_count;
1045+
// MDW 2013-04-16: was comparing signed and unsigned values
1046+
uint32_t t_new_tile_count;
10451047
t_new_tile_count = 0;
10461048
for(uint32_t i = 0; i < t_cell -> tile_count; i++)
10471049
{

0 commit comments

Comments
 (0)