summaryrefslogtreecommitdiffstats
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
parent1245c5fe61f6ca8e1980a33a8b8f7ea4322829fd (diff)
downloadrockbox-d787191.tar.gz
rockbox-d787191.tar.bz2
rockbox-d787191.zip
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
-rw-r--r--apps/gui/skin_engine/skin_parser.c2
-rw-r--r--apps/misc.c2
-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
-rw-r--r--apps/recorder/keyboard.c2
-rw-r--r--apps/tagcache.c10
-rw-r--r--firmware/asm/memset16.c3
-rw-r--r--firmware/drivers/lcd-16bit-common.c10
-rw-r--r--firmware/drivers/lcd-16bit.c2
-rw-r--r--firmware/drivers/lcd-color-common.c2
-rw-r--r--firmware/kernel/queue.c4
-rw-r--r--firmware/target/hosted/filesystem-win32.c2
-rw-r--r--lib/rbcodec/codecs/liba52/bitstream.c2
-rw-r--r--lib/rbcodec/codecs/libtremor/codebook.c6
-rw-r--r--lib/rbcodec/metadata/id3tags.c6
-rw-r--r--lib/tlsf/src/tlsf.c7
27 files changed, 69 insertions, 66 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index 63f3f81140..5409861cc7 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -2493,7 +2493,7 @@ bool skin_data_load(enum screen_type screen, struct wps_data *wps_data,
skin_buffer = wps_buffer;
wps_buffer = (char*)buf;
}
- skin_buffer = (void *)(((unsigned long)skin_buffer + 3) & ~3);
+ skin_buffer = ALIGN_UP(skin_buffer, 4); /* align on 4-byte boundary */
buffersize -= 3;
#ifdef HAVE_BACKDROP_IMAGE
backdrop_filename = "-";
diff --git a/apps/misc.c b/apps/misc.c
index e460eb542c..3fdcab85e6 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -215,7 +215,7 @@ int fast_readline(int fd, char *buf, int buf_size, void *parameters,
count++;
if (next)
{
- pos = buf_size - ((long)next - (long)buf) - 1;
+ pos = buf_size - ((intptr_t)next - (intptr_t)buf) - 1;
memmove(buf, next, pos);
}
else
diff --git a/apps/plugins/doom/d_deh.c b/apps/plugins/doom/d_deh.c
index abdaeae9ae..1a399e3b49 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 be45e6a37e..1afeffa502 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 a704bfa83c..891b3b0503 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 df00d6a9d7..d2b6111b60 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 bb78316346..206606a4bb 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 06cc9c1a71..6927d84a96 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 1b552ee15c..9ad3594287 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 392e78e77f..c7f36968a1 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 acd514ad39..78d7b52045 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 b5e982d208..b476fa11b4 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 468f46667e..74845bac8e 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 b030f8dab9..054cae1aba 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 f6f1de7468..683584f471 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);
}
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index fed8605714..ceb8de00fb 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -255,7 +255,7 @@ static void kbd_inschar(struct edit_state *state, unsigned short ch)
len = strlen(state->text);
utf8 = utf8encode(ch, tmp);
- j = (long)utf8 - (long)tmp;
+ j = (intptr_t)utf8 - (intptr_t)tmp;
if (len + j < state->buflen)
{
diff --git a/apps/tagcache.c b/apps/tagcache.c
index df252ca0bc..2b3c7212a2 100644
--- a/apps/tagcache.c
+++ b/apps/tagcache.c
@@ -930,7 +930,7 @@ inline static bool str_oneof(const char *str, const char *list)
while (*list)
{
sep = strchr(list, '|');
- l = sep ? (long)sep - (long)list : (int)strlen(list);
+ l = sep ? (intptr_t)sep - (intptr_t)list : (int)strlen(list);
if ((l==len) && !strncasecmp(str, list, len))
return true;
list += sep ? l + 1 : l;
@@ -2362,7 +2362,7 @@ static bool build_numeric_indices(struct tagcache_header *h, int tmpfd)
/* Avoid processing this entry again. */
idx.flag |= FLAG_RESURRECTED;
- lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
+ lseek(masterfd, -(off_t)sizeof(struct index_entry), SEEK_CUR);
if (ecwrite_index_entry(masterfd, &idx) != sizeof(struct index_entry))
{
logf("masterfd writeback fail #1");
@@ -3432,7 +3432,7 @@ static int parse_changelog_line(int line_n, char *buf, void *parameters)
struct index_entry idx;
char tag_data[TAG_MAXLEN+32];
int idx_id;
- long masterfd = (long)parameters;
+ long masterfd = (long)(intptr_t)parameters;
const int import_tags[] = { tag_playcount, tag_rating, tag_playtime,
tag_lastplayed, tag_commitid, tag_lastelapsed,
tag_lastoffset };
@@ -3526,7 +3526,7 @@ bool tagcache_import_changelog(void)
filenametag_fd = open_tag_fd(&tch, tag_filename, false);
- fast_readline(clfd, buf, sizeof buf, (long *)masterfd,
+ fast_readline(clfd, buf, sizeof buf, (void *)(intptr_t)masterfd,
parse_changelog_line);
close(clfd);
@@ -3665,7 +3665,7 @@ static bool delete_entry(long idx_id)
}
myidx.flag |= FLAG_DELETED;
- lseek(masterfd, -sizeof(struct index_entry), SEEK_CUR);
+ lseek(masterfd, -(off_t)sizeof(struct index_entry), SEEK_CUR);
if (ecwrite_index_entry(masterfd, &myidx) != sizeof(struct index_entry))
{
logf("delete_entry(): write_error #1");
diff --git a/firmware/asm/memset16.c b/firmware/asm/memset16.c
index db71d86fcc..12f3388a8d 100644
--- a/firmware/asm/memset16.c
+++ b/firmware/asm/memset16.c
@@ -20,9 +20,10 @@
****************************************************************************/
#include "string-extra.h" /* memset16() */
+#include <stdint.h>
#define LBLOCKSIZE (sizeof(long)/2)
-#define ROCKBOX_UNALIGNED(X) ((long)X & (sizeof(long) - 1))
+#define ROCKBOX_UNALIGNED(X) ((uintptr_t)X & (sizeof(long) - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
void memset16(void *dst, int val, size_t len)
diff --git a/firmware/drivers/lcd-16bit-common.c b/firmware/drivers/lcd-16bit-common.c
index d006b3900a..a7e80c7244 100644
--- a/firmware/drivers/lcd-16bit-common.c
+++ b/firmware/drivers/lcd-16bit-common.c
@@ -94,7 +94,7 @@ void lcd_clear_viewport(void)
{
do
{
- memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
+ memcpy(dst, PTR_ADD(dst, lcd_backdrop_offset),
len * sizeof(fb_data));
dst += step;
}
@@ -122,7 +122,7 @@ static void ICODE_ATTR clearpixel(fb_data *address)
static void ICODE_ATTR clearimgpixel(fb_data *address)
{
- *address = *(fb_data *)((long)address + lcd_backdrop_offset);
+ *address = *PTR_ADD(address, lcd_backdrop_offset);
}
static void ICODE_ATTR flippixel(fb_data *address)
@@ -244,7 +244,7 @@ void lcd_fillrect(int x, int y, int width, int height)
break;
case OPT_COPY:
- memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
+ memcpy(dst, PTR_ADD(dst, lcd_backdrop_offset),
len * sizeof(fb_data));
break;
@@ -395,7 +395,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
do
{
if (!(data & 0x01))
- *dst = *(fb_data *)((long)dst + bo);
+ *dst = *PTR_ADD(dst, bo);
dst += ROW_INC;
UPDATE_SRC;
@@ -435,7 +435,7 @@ void ICODE_ATTR lcd_mono_bitmap_part(const unsigned char *src, int src_x,
do
{
*dst = (data & 0x01) ? fg
- : *(fb_data *)((long)dst + bo);
+ : *PTR_ADD(dst, bo);
dst += ROW_INC;
UPDATE_SRC;
}
diff --git a/firmware/drivers/lcd-16bit.c b/firmware/drivers/lcd-16bit.c
index 3c99560b6d..b792be4e02 100644
--- a/firmware/drivers/lcd-16bit.c
+++ b/firmware/drivers/lcd-16bit.c
@@ -139,7 +139,7 @@ void lcd_hline(int x1, int x2, int y)
break;
case OPT_COPY:
- memcpy(dst, (void *)((long)dst + lcd_backdrop_offset),
+ memcpy(dst, PTR_ADD(dst, lcd_backdrop_offset),
width * sizeof(fb_data));
break;
diff --git a/firmware/drivers/lcd-color-common.c b/firmware/drivers/lcd-color-common.c
index b5b0f58eb3..c8bfd2d6b3 100644
--- a/firmware/drivers/lcd-color-common.c
+++ b/firmware/drivers/lcd-color-common.c
@@ -148,7 +148,7 @@ void lcd_set_backdrop(fb_data* backdrop)
lcd_backdrop = backdrop;
if (backdrop)
{
- lcd_backdrop_offset = (long)backdrop - (long)lcd_framebuffer;
+ lcd_backdrop_offset = (intptr_t)backdrop - (intptr_t)lcd_framebuffer;
lcd_fastpixelfuncs = lcd_fastpixelfuncs_backdrop;
}
else
diff --git a/firmware/kernel/queue.c b/firmware/kernel/queue.c
index 233b53c364..5566604c5d 100644
--- a/firmware/kernel/queue.c
+++ b/firmware/kernel/queue.c
@@ -418,7 +418,7 @@ void queue_post(struct event_queue *q, long id, intptr_t data)
wr = q->write++ & QUEUE_LENGTH_MASK;
KERNEL_ASSERT((q->write - q->read) <= QUEUE_LENGTH,
- "queue_post ovf q=%08lX", (long)q);
+ "queue_post ovf q=%p", q);
q->events[wr].id = id;
q->events[wr].data = data;
@@ -450,7 +450,7 @@ intptr_t queue_send(struct event_queue *q, long id, intptr_t data)
wr = q->write++ & QUEUE_LENGTH_MASK;
KERNEL_ASSERT((q->write - q->read) <= QUEUE_LENGTH,
- "queue_send ovf q=%08lX", (long)q);
+ "queue_send ovf q=%p", q);
q->events[wr].id = id;
q->events[wr].data = data;
diff --git a/firmware/target/hosted/filesystem-win32.c b/firmware/target/hosted/filesystem-win32.c
index fad9b16e36..be95134cc9 100644
--- a/firmware/target/hosted/filesystem-win32.c
+++ b/firmware/target/hosted/filesystem-win32.c
@@ -251,7 +251,7 @@ int os_opendirfd(const char *osdirname)
else
{
/* Convert OS handle to fd; the fd now owns it */
- int osfd = _open_osfhandle((long)h, O_RDONLY);
+ int osfd = _open_osfhandle((intptr_t)h, O_RDONLY);
if (osfd >= 0)
return osfd;
}
diff --git a/lib/rbcodec/codecs/liba52/bitstream.c b/lib/rbcodec/codecs/liba52/bitstream.c
index 155368f1ed..69dd1dc5b7 100644
--- a/lib/rbcodec/codecs/liba52/bitstream.c
+++ b/lib/rbcodec/codecs/liba52/bitstream.c
@@ -35,7 +35,7 @@ void a52_bitstream_set_ptr (a52_state_t * state, uint8_t * buf)
{
int align;
- align = (long)buf & 3;
+ align = (intptr_t)buf & 3;
state->buffer_start = (uint32_t *) (buf - align);
state->bits_left = 0;
state->current_word = 0;
diff --git a/lib/rbcodec/codecs/libtremor/codebook.c b/lib/rbcodec/codecs/libtremor/codebook.c
index 7087f0a323..f3ac5a2b7e 100644
--- a/lib/rbcodec/codecs/libtremor/codebook.c
+++ b/lib/rbcodec/codecs/libtremor/codebook.c
@@ -293,7 +293,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
if(b->endbyte < b->storage - 8) {
ogg_uint32_t *ptr;
unsigned long bit, bitend;
- unsigned long adr;
+ intptr_t adr;
ogg_uint32_t cache = 0;
int cachesize = 0;
const unsigned int cachemask = (1<<book->dec_firsttablen)-1;
@@ -303,7 +303,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
const ogg_uint32_t *book_codelist = book->codelist;
const char *book_dec_codelengths = book->dec_codelengths;
- adr = (unsigned long)b->ptr;
+ adr = (intptr_t)b->ptr;
bit = (adr&3)*8+b->endbit;
ptr = (ogg_uint32_t*)(adr&~3);
bitend = ((adr&3)+(b->storage-b->endbyte))*8;
@@ -334,7 +334,7 @@ static long decode_packed_block(codebook *book, oggpack_buffer *b,
cache >>= l;
}
- adr=(unsigned long)b->ptr;
+ adr=(intptr_t)b->ptr;
bit-=(adr&3)*8+cachesize;
b->endbyte+=bit/8;
b->ptr+=bit/8;
diff --git a/lib/rbcodec/metadata/id3tags.c b/lib/rbcodec/metadata/id3tags.c
index 3492197c40..cda8ce3b7a 100644
--- a/lib/rbcodec/metadata/id3tags.c
+++ b/lib/rbcodec/metadata/id3tags.c
@@ -191,7 +191,7 @@ static int unsynchronize(char* tag, int len, bool *ff_found)
wp++;
}
}
- return (long)wp - (long)tag;
+ return (intptr_t)wp - (intptr_t)tag;
}
static int unsynchronize_frame(char* tag, int len)
@@ -562,7 +562,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) {
(*len)--;
utf8 = iso_decode(str, utf8, -1, *len);
*utf8 = 0;
- *len = (unsigned long)utf8 - (unsigned long)utf8buf;
+ *len = (intptr_t)utf8 - (intptr_t)utf8buf;
break;
case 0x01: /* Unicode with or without BOM */
@@ -619,7 +619,7 @@ static int unicode_munge(char* string, char* utf8buf, int *len) {
default: /* Plain old string */
utf8 = iso_decode(str, utf8, -1, *len);
*utf8 = 0;
- *len = (unsigned long)utf8 - (unsigned long)utf8buf;
+ *len = (intptr_t)utf8 - (intptr_t)utf8buf;
break;
}
return 0;
diff --git a/lib/tlsf/src/tlsf.c b/lib/tlsf/src/tlsf.c
index 6866f0c9b0..136c4152c0 100644
--- a/lib/tlsf/src/tlsf.c
+++ b/lib/tlsf/src/tlsf.c
@@ -54,6 +54,7 @@
#include <stdio.h>
#include <string.h>
+#include <stdint.h>
#ifndef TLSF_USE_LOCKS
#define TLSF_USE_LOCKS (0)
@@ -462,7 +463,7 @@ size_t init_memory_pool(size_t mem_pool_size, void *mem_pool)
return -1;
}
- if (((unsigned long) mem_pool & PTR_MASK)) {
+ if (((intptr_t) mem_pool & PTR_MASK)) {
ERROR_MSG("init_memory_pool (): mem_pool must be aligned to a word\n");
return -1;
}
@@ -522,7 +523,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool)
lb1 = ptr->end;
/* Merging the new area with the next physically contigous one */
- if ((unsigned long) ib1 == (unsigned long) lb0 + BHDR_OVERHEAD) {
+ if ((uintptr_t) ib1 == (uintptr_t) lb0 + BHDR_OVERHEAD) {
if (tlsf->area_head == ptr) {
tlsf->area_head = ptr->next;
ptr = ptr->next;
@@ -543,7 +544,7 @@ size_t add_new_area(void *area, size_t area_size, void *mem_pool)
/* Merging the new area with the previous physically contigous
one */
- if ((unsigned long) lb1->ptr.buffer == (unsigned long) ib0) {
+ if ((intptr_t) lb1->ptr.buffer == (intptr_t) ib0) {
if (tlsf->area_head == ptr) {
tlsf->area_head = ptr->next;
ptr = ptr->next;