summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-01-16 00:10:38 +0100
committerGerrit Rockbox <gerrit@rockbox.org>2017-02-04 17:24:47 +0100
commitd7871914acd2ed77f43344e36e08944524a67d9e (patch)
tree7bcef243d9b53c3703c305b8a5f9f8a8488eabfb /apps/plugins
parent1245c5fe61f6ca8e1980a33a8b8f7ea4322829fd (diff)
downloadrockbox-d7871914acd2ed77f43344e36e08944524a67d9e.zip
rockbox-d7871914acd2ed77f43344e36e08944524a67d9e.tar.gz
rockbox-d7871914acd2ed77f43344e36e08944524a67d9e.tar.bz2
rockbox-d7871914acd2ed77f43344e36e08944524a67d9e.tar.xz
Fix dangerous casts
On Windows 64-bit, the size of long is 32-bit, thus any pointer to long cast is not valid. In any case, one should use intptr_t and ptrdiff_t when casting to integers. This commit attempts to fix all instances reported by GCC. When relevant, I replaced code by the macros PTR_ADD, ALIGN_UP from system.h Change-Id: I2273b0e8465d3c4689824717ed5afa5ed238a2dc
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/doom/d_deh.c4
-rw-r--r--apps/plugins/doom/d_main.c2
-rw-r--r--apps/plugins/doom/p_saveg.c30
-rw-r--r--apps/plugins/doom/z_zone.c4
-rw-r--r--apps/plugins/goban/util.c4
-rw-r--r--apps/plugins/lib/simple_viewer.c2
-rw-r--r--apps/plugins/lib/strncpy.c3
-rw-r--r--apps/plugins/lrcplayer.c16
-rw-r--r--apps/plugins/mikmod/mikmod_internals.h2
-rw-r--r--apps/plugins/solitaire.c2
-rw-r--r--apps/plugins/zxbox/snapshot.c2
-rw-r--r--apps/plugins/zxbox/tapefile.c2
-rw-r--r--apps/plugins/zxbox/z80.c2
13 files changed, 38 insertions, 37 deletions
diff --git a/apps/plugins/doom/d_deh.c b/apps/plugins/doom/d_deh.c
index abdaeae..1a399e3 100644
--- a/apps/plugins/doom/d_deh.c
+++ b/apps/plugins/doom/d_deh.c
@@ -2082,7 +2082,7 @@ void deh_procSounds(DEHFILE *fpin, int fpout, char *line)
S_sfx[indexnum].priority = (int)value;
else
if (!strcasecmp(key,deh_sfxinfo[3])) // Zero 1
- S_sfx[indexnum].link = (sfxinfo_t *)((long) value);
+ S_sfx[indexnum].link = (sfxinfo_t *)((intptr_t) value);
else
if (!strcasecmp(key,deh_sfxinfo[4])) // Zero 2
S_sfx[indexnum].pitch = (int)value;
@@ -2091,7 +2091,7 @@ void deh_procSounds(DEHFILE *fpin, int fpout, char *line)
S_sfx[indexnum].volume = (int)value;
else
if (!strcasecmp(key,deh_sfxinfo[6])) // Zero 4
- S_sfx[indexnum].data = (void *) ((long) value); // killough 5/3/98: changed cast
+ S_sfx[indexnum].data = (void *) ((intptr_t) value); // killough 5/3/98: changed cast
else
if (!strcasecmp(key,deh_sfxinfo[7])) // Neg. One 1
S_sfx[indexnum].usefulness = (int)value;
diff --git a/apps/plugins/doom/d_main.c b/apps/plugins/doom/d_main.c
index be45e6a..1afeffa 100644
--- a/apps/plugins/doom/d_main.c
+++ b/apps/plugins/doom/d_main.c
@@ -807,7 +807,7 @@ void D_DoomMainSetup(void)
// for statistics driver
extern void* statcopy;
- statcopy = (void*)(long)atoi(myargv[p+1]);
+ statcopy = (void*)(intptr_t)atoi(myargv[p+1]);
printf ("External statistics registered.\n");
}
diff --git a/apps/plugins/doom/p_saveg.c b/apps/plugins/doom/p_saveg.c
index a704bfa..891b3b0 100644
--- a/apps/plugins/doom/p_saveg.c
+++ b/apps/plugins/doom/p_saveg.c
@@ -44,7 +44,7 @@ byte *save_p;
// Pads save_p to a 4-byte boundary
// so that the load/save works on SGI&Gecko.
-#define PADSAVEP() do { save_p += (4 - ((unsigned long) save_p & 3)) & 3; } while (0)
+#define PADSAVEP() do { save_p += (4 - ((intptr_t) save_p & 3)) & 3; } while (0)
//
// P_ArchivePlayers
//
@@ -95,7 +95,7 @@ void P_UnArchivePlayers (void)
for (j=0 ; j<NUMPSPRITES ; j++)
if (players[i]. psprites[j].state)
players[i]. psprites[j].state =
- &states[ (unsigned long)players[i].psprites[j].state ];
+ &states[ (intptr_t)players[i].psprites[j].state ];
}
}
@@ -270,7 +270,7 @@ void P_ThinkerToIndex(void)
number_of_thinkers = 0;
for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
if (th->function == P_MobjThinker)
- th->prev = (thinker_t *)(long)(++number_of_thinkers);
+ th->prev = (thinker_t *)(intptr_t)(++number_of_thinkers);
}
// phares 9/13/98: Moved this code outside of P_ArchiveThinkers so the
@@ -448,10 +448,10 @@ void P_UnArchiveThinkers (void)
PADSAVEP();
memcpy (mobj, save_p, sizeof(mobj_t));
save_p += sizeof(mobj_t);
- mobj->state = states + (unsigned long) mobj->state;
+ mobj->state = states + (intptr_t) mobj->state;
if (mobj->player)
- (mobj->player = &players[(unsigned long) mobj->player - 1]) -> mo = mobj;
+ (mobj->player = &players[(intptr_t) mobj->player - 1]) -> mo = mobj;
P_SetThingPosition (mobj);
mobj->info = &mobjinfo[mobj->type];
@@ -770,7 +770,7 @@ void P_UnArchiveSpecials (void)
ceiling_t *ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVEL, NULL);
memcpy (ceiling, save_p, sizeof(*ceiling));
save_p += sizeof(*ceiling);
- ceiling->sector = &sectors[(unsigned long)ceiling->sector];
+ ceiling->sector = &sectors[(intptr_t)ceiling->sector];
ceiling->sector->ceilingdata = ceiling; //jff 2/22/98
if (ceiling->thinker.function)
@@ -787,10 +787,10 @@ void P_UnArchiveSpecials (void)
vldoor_t *door = Z_Malloc (sizeof(*door), PU_LEVEL, NULL);
memcpy (door, save_p, sizeof(*door));
save_p += sizeof(*door);
- door->sector = &sectors[(unsigned long)door->sector];
+ door->sector = &sectors[(intptr_t)door->sector];
//jff 1/31/98 unarchive line remembered by door as well
- door->line = (long)door->line!=-1? &lines[(unsigned long)door->line] : NULL;
+ door->line = (intptr_t)door->line!=-1? &lines[(intptr_t)door->line] : NULL;
door->sector->ceilingdata = door; //jff 2/22/98
door->thinker.function = T_VerticalDoor;
@@ -804,7 +804,7 @@ void P_UnArchiveSpecials (void)
floormove_t *floor = Z_Malloc (sizeof(*floor), PU_LEVEL, NULL);
memcpy (floor, save_p, sizeof(*floor));
save_p += sizeof(*floor);
- floor->sector = &sectors[(unsigned long)floor->sector];
+ floor->sector = &sectors[(intptr_t)floor->sector];
floor->sector->floordata = floor; //jff 2/22/98
floor->thinker.function = T_MoveFloor;
P_AddThinker (&floor->thinker);
@@ -817,7 +817,7 @@ void P_UnArchiveSpecials (void)
plat_t *plat = Z_Malloc (sizeof(*plat), PU_LEVEL, NULL);
memcpy (plat, save_p, sizeof(*plat));
save_p += sizeof(*plat);
- plat->sector = &sectors[(unsigned long)plat->sector];
+ plat->sector = &sectors[(intptr_t)plat->sector];
plat->sector->floordata = plat; //jff 2/22/98
if (plat->thinker.function)
@@ -834,7 +834,7 @@ void P_UnArchiveSpecials (void)
lightflash_t *flash = Z_Malloc (sizeof(*flash), PU_LEVEL, NULL);
memcpy (flash, save_p, sizeof(*flash));
save_p += sizeof(*flash);
- flash->sector = &sectors[(unsigned long)flash->sector];
+ flash->sector = &sectors[(intptr_t)flash->sector];
flash->thinker.function = T_LightFlash;
P_AddThinker (&flash->thinker);
break;
@@ -846,7 +846,7 @@ void P_UnArchiveSpecials (void)
strobe_t *strobe = Z_Malloc (sizeof(*strobe), PU_LEVEL, NULL);
memcpy (strobe, save_p, sizeof(*strobe));
save_p += sizeof(*strobe);
- strobe->sector = &sectors[(unsigned long)strobe->sector];
+ strobe->sector = &sectors[(intptr_t)strobe->sector];
strobe->thinker.function = T_StrobeFlash;
P_AddThinker (&strobe->thinker);
break;
@@ -858,7 +858,7 @@ void P_UnArchiveSpecials (void)
glow_t *glow = Z_Malloc (sizeof(*glow), PU_LEVEL, NULL);
memcpy (glow, save_p, sizeof(*glow));
save_p += sizeof(*glow);
- glow->sector = &sectors[(unsigned long)glow->sector];
+ glow->sector = &sectors[(intptr_t)glow->sector];
glow->thinker.function = T_Glow;
P_AddThinker (&glow->thinker);
break;
@@ -870,7 +870,7 @@ void P_UnArchiveSpecials (void)
fireflicker_t *flicker = Z_Malloc (sizeof(*flicker), PU_LEVEL, NULL);
memcpy (flicker, save_p, sizeof(*flicker));
save_p += sizeof(*flicker);
- flicker->sector = &sectors[(unsigned long)flicker->sector];
+ flicker->sector = &sectors[(intptr_t)flicker->sector];
flicker->thinker.function = T_FireFlicker;
P_AddThinker (&flicker->thinker);
break;
@@ -883,7 +883,7 @@ void P_UnArchiveSpecials (void)
elevator_t *elevator = Z_Malloc (sizeof(*elevator), PU_LEVEL, NULL);
memcpy (elevator, save_p, sizeof(*elevator));
save_p += sizeof(*elevator);
- elevator->sector = &sectors[(unsigned long)elevator->sector];
+ elevator->sector = &sectors[(intptr_t)elevator->sector];
elevator->sector->floordata = elevator; //jff 2/22/98
elevator->sector->ceilingdata = elevator; //jff 2/22/98
elevator->thinker.function = T_MoveElevator;
diff --git a/apps/plugins/doom/z_zone.c b/apps/plugins/doom/z_zone.c
index df00d6a..d2b6111 100644
--- a/apps/plugins/doom/z_zone.c
+++ b/apps/plugins/doom/z_zone.c
@@ -252,8 +252,8 @@ void Z_Init(void)
// Align on cache boundary
- zone = (memblock_t *) ((unsigned long)zonebase + CACHE_ALIGN -
- ((unsigned long)zonebase & (CACHE_ALIGN-1)));
+ zone = (memblock_t *) ((intptr_t)zonebase + CACHE_ALIGN -
+ ((intptr_t)zonebase & (CACHE_ALIGN-1)));
rover = zone; // Rover points to base of zone mem
zone->next = zone->prev = zone; // Single node
diff --git a/apps/plugins/goban/util.c b/apps/plugins/goban/util.c
index bb78316..206606a 100644
--- a/apps/plugins/goban/util.c
+++ b/apps/plugins/goban/util.c
@@ -73,7 +73,7 @@ void metadata_summary (void)
void *
align_buffer (void *buffer, size_t * buffer_size)
{
- unsigned int wasted = (-(long) buffer) & 3;
+ unsigned int wasted = (-(intptr_t) buffer) & 3;
if (!buffer || !buffer_size)
{
@@ -88,7 +88,7 @@ align_buffer (void *buffer, size_t * buffer_size)
*buffer_size -= wasted;
- return (void *) (((char *) buffer) + wasted);
+ return PTR_ADD(buffer, wasted);
}
diff --git a/apps/plugins/lib/simple_viewer.c b/apps/plugins/lib/simple_viewer.c
index 06cc9c1..6927d84 100644
--- a/apps/plugins/lib/simple_viewer.c
+++ b/apps/plugins/lib/simple_viewer.c
@@ -69,7 +69,7 @@ static const char* get_next_line(const char *text, struct view_info *info)
w = 1;
#else
unsigned short ch;
- n = ((long)rb->utf8decode(ptr, &ch) - (long)ptr);
+ n = ((intptr_t)rb->utf8decode(ptr, &ch) - (intptr_t)ptr);
if (rb->is_diacritic(ch, NULL))
w = 0;
else
diff --git a/apps/plugins/lib/strncpy.c b/apps/plugins/lib/strncpy.c
index 1b552ee..9ad3594 100644
--- a/apps/plugins/lib/strncpy.c
+++ b/apps/plugins/lib/strncpy.c
@@ -41,13 +41,14 @@ QUICKREF
#include <limits.h>
#include "plugin.h"
#include "_ansi.h"
+#include <stdint.h>
/*SUPPRESS 560*/
/*SUPPRESS 530*/
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
#define ROCKBOX_UNALIGNED(X, Y) \
- (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
+ (((uintptr_t)X & (sizeof (long) - 1)) | ((uintptr_t)Y & (sizeof (long) - 1)))
#if LONG_MAX == 2147483647L
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
diff --git a/apps/plugins/lrcplayer.c b/apps/plugins/lrcplayer.c
index 392e78e..c7f3696 100644
--- a/apps/plugins/lrcplayer.c
+++ b/apps/plugins/lrcplayer.c
@@ -545,7 +545,7 @@ static struct lrc_brpos *calc_brpos(struct lrc_line *lrc_line, int i)
c = rb->utf8seek(cr.str, 1);
w = 1;
#else
- c = ((long)rb->utf8decode(cr.str, &ch) - (long)cr.str);
+ c = ((intptr_t)rb->utf8decode(cr.str, &ch) - (intptr_t)cr.str);
if (rb->is_diacritic(ch, NULL))
w = 0;
else
@@ -885,7 +885,7 @@ static bool parse_lrc_line(char *line, off_t file_offset)
lrc_line->time_start = (time/10)*10;
lrc_line->old_time_start = lrc_line->time_start;
add_lrc_line(lrc_line, NULL);
- file_offset += (long)tagend - (long)str;
+ file_offset += (intptr_t)tagend - (intptr_t)str;
str = tagend;
}
if (!first_lrc_line)
@@ -908,7 +908,7 @@ static bool parse_lrc_line(char *line, off_t file_offset)
if (!tagend) break;
*tagend = 0;
time = get_time_value(tagstart+1, false,
- file_offset + ((long)tagstart - (long)str));
+ file_offset + ((intptr_t)tagstart - (intptr_t)str));
*tagend++ = '>';
if (time < 0)
{
@@ -923,7 +923,7 @@ static bool parse_lrc_line(char *line, off_t file_offset)
return false;
nword++;
}
- file_offset += (long)tagend - (long)str;
+ file_offset += (intptr_t)tagend - (intptr_t)str;
tagstart = str = tagend;
time_start = time;
}
@@ -1159,7 +1159,7 @@ static int unsynchronize(char* tag, int len, bool *ff_found)
}
}
if(ff_found) *ff_found = _ff_found;
- return (long)wp - (long)tag;
+ return (intptr_t)wp - (intptr_t)tag;
}
static int read_unsynched(int fd, void *buf, int len, bool *ff_found)
@@ -1471,7 +1471,7 @@ static void parse_id3v2(int fd)
utf_decode = rb->utf16BEdecode;
}
}
- bytesread -= (long)p - (long)tag;
+ bytesread -= (intptr_t)p - (intptr_t)tag;
tag = p;
while ( bytesread > 0
@@ -1529,7 +1529,7 @@ static void parse_id3v2(int fd)
lrc_line->old_time_start = -1;
if(is_crlf) p += chsiz;
}
- bytesread -= (long)p - (long)tag;
+ bytesread -= (intptr_t)p - (intptr_t)tag;
tag = p;
if(!add_lrc_line(lrc_line, utf8line))
break;
@@ -2922,7 +2922,7 @@ enum plugin_status plugin_start(const void* parameter)
#endif
lrc_buffer = rb->plugin_get_buffer(&lrc_buffer_size);
- lrc_buffer = (void *)(((long)lrc_buffer+3)&~3); /* 4 bytes aligned */
+ lrc_buffer = ALIGN_UP(lrc_buffer, 4); /* 4 bytes aligned */
lrc_buffer_size = (lrc_buffer_size - 4)&~3;
reset_current_data();
diff --git a/apps/plugins/mikmod/mikmod_internals.h b/apps/plugins/mikmod/mikmod_internals.h
index acd514a..78d7b52 100644
--- a/apps/plugins/mikmod/mikmod_internals.h
+++ b/apps/plugins/mikmod/mikmod_internals.h
@@ -703,7 +703,7 @@ extern int Voice_Stopped_internal(SBYTE);
/*========== SIMD mixing helper functions =============*/
-#define IS_ALIGNED_16(ptr) (!(((int)(ptr)) & 15))
+#define IS_ALIGNED_16(ptr) (!(((intptr_t)(ptr)) & 15))
/* Altivec helper function */
#if defined HAVE_ALTIVEC
diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c
index b5e982d..b476fa1 100644
--- a/apps/plugins/solitaire.c
+++ b/apps/plugins/solitaire.c
@@ -1547,7 +1547,7 @@ static int load_game( void )
return -1;
retval = 0; /* Assume good case */
- if( ( rb->lseek( fd, -sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
+ if( ( rb->lseek( fd, -(off_t)sizeof( int ), SEEK_END ) == -((ssize_t)sizeof( int ))-1 )
|| ( rb->read( fd, &checksum, sizeof( int ) ) < ((ssize_t)sizeof( int )) )
|| ( rb->lseek( fd, 0, SEEK_SET ) == -1 )
|| save_read( fd, &cur_card, sizeof( int ), &checksum )
diff --git a/apps/plugins/zxbox/snapshot.c b/apps/plugins/zxbox/snapshot.c
index 468f466..74845ba 100644
--- a/apps/plugins/zxbox/snapshot.c
+++ b/apps/plugins/zxbox/snapshot.c
@@ -362,7 +362,7 @@ static void read_compressed_data(SNFILE *fp, byte *start, unsigned size,
GET_DATA(ch);
if(p + times > end) {
put_msg("Warning: Repeat parameter too large in snapshot");
- times = (int) ((long) end - (long) p);
+ times = (int) ((intptr_t) end - (intptr_t) p);
}
for(j = 0; j < times; j++) *p++ = ch;
}
diff --git a/apps/plugins/zxbox/tapefile.c b/apps/plugins/zxbox/tapefile.c
index b030f8d..054cae1 100644
--- a/apps/plugins/zxbox/tapefile.c
+++ b/apps/plugins/zxbox/tapefile.c
@@ -216,7 +216,7 @@ static struct tzxblock tzxb[NUMBLOCKID] = {
};
-#define PTRDIFF(pe, ps) ((int) (((long) (pe) - (long) (ps)) / sizeof(*pe)))
+#define PTRDIFF(pe, ps) pe - ps
static char tzxheader[] = {'Z','X','T','a','p','e','!',0x1A};
diff --git a/apps/plugins/zxbox/z80.c b/apps/plugins/zxbox/z80.c
index f6f1de7..683584f 100644
--- a/apps/plugins/zxbox/z80.c
+++ b/apps/plugins/zxbox/z80.c
@@ -48,7 +48,7 @@ static byte *a64kmalloc(int num64ksegs)
/*exit(1);*/
}
- return (byte *) (( (long) bigmem & ~((long) 0xFFFF)) + 0x10000);
+ return (byte *) (( (intptr_t) bigmem & ~((intptr_t) 0xFFFF)) + 0x10000);
}