diff options
author | Franklin Wei <git@fwei.tk> | 2019-07-24 21:01:44 -0400 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2019-07-24 21:02:11 -0400 |
commit | 7e4902bf6bfcf0acef0889bf4e3fae04a8839079 (patch) | |
tree | 27af47d9ca18184c0f52c76282284c6fa016148e /apps/plugins | |
parent | 7bef453e0318acee10adbc2b561ba7d2f4b81fe3 (diff) | |
download | rockbox-7e4902bf6bfcf0acef0889bf4e3fae04a8839079.tar.gz rockbox-7e4902bf6bfcf0acef0889bf4e3fae04a8839079.zip |
quake: fix errorneous endian-correcting reads
ef9ee89 introduced Read{Big,Little}{Short,Long,Float} functions to safely
read a value in memory. These incorrectly take char*, which causes them to
output erroneous 0xff bytes when given bytes with bit 7 set.
Change-Id: I9531172301aecfdacae405d2f782f662608ce6df
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/sdl/progs/quake/common.c | 12 | ||||
-rw-r--r-- | apps/plugins/sdl/progs/quake/common.h | 24 | ||||
-rw-r--r-- | apps/plugins/sdl/progs/quake/model.c | 6 |
3 files changed, 23 insertions, 19 deletions
diff --git a/apps/plugins/sdl/progs/quake/common.c b/apps/plugins/sdl/progs/quake/common.c index 5e842b09ae..5191af8c36 100644 --- a/apps/plugins/sdl/progs/quake/common.c +++ b/apps/plugins/sdl/progs/quake/common.c | |||
@@ -499,28 +499,28 @@ float FloatNoSwap (float f) | |||
499 | } | 499 | } |
500 | 500 | ||
501 | // safe for unaligned accesses | 501 | // safe for unaligned accesses |
502 | short ReadLittleShort (char *l) | 502 | short ReadLittleShort (unsigned char *l) |
503 | { | 503 | { |
504 | return *(l + 0) | (*(l + 1) << 8); | 504 | return *(l + 0) | (*(l + 1) << 8); |
505 | } | 505 | } |
506 | 506 | ||
507 | short ReadBigShort (char *l) | 507 | short ReadBigShort (unsigned char *l) |
508 | { | 508 | { |
509 | return *(l + 1) | (*(l + 0) << 8); | 509 | return *(l + 1) | (*(l + 0) << 8); |
510 | } | 510 | } |
511 | 511 | ||
512 | int ReadLittleLong (char *l) | 512 | int ReadLittleLong (unsigned char *l) |
513 | { | 513 | { |
514 | return *(l + 0) | (*(l + 1) << 8) | (*(l + 2) << 16) | (*(l + 3) << 24); | 514 | return *(l + 0) | (*(l + 1) << 8) | (*(l + 2) << 16) | (*(l + 3) << 24); |
515 | } | 515 | } |
516 | 516 | ||
517 | int ReadBigLong (char *l) | 517 | int ReadBigLong (unsigned char *l) |
518 | { | 518 | { |
519 | return *(l + 3) | (*(l + 2) << 8) | (*(l + 1) << 16) | (*(l + 0) << 24); | 519 | return *(l + 3) | (*(l + 2) << 8) | (*(l + 1) << 16) | (*(l + 0) << 24); |
520 | } | 520 | } |
521 | 521 | ||
522 | // same | 522 | // same |
523 | float ReadLittleFloat (char *f) | 523 | float ReadLittleFloat (unsigned char *f) |
524 | { | 524 | { |
525 | union | 525 | union |
526 | { | 526 | { |
@@ -536,7 +536,7 @@ float ReadLittleFloat (char *f) | |||
536 | return dat2.f; | 536 | return dat2.f; |
537 | } | 537 | } |
538 | 538 | ||
539 | float ReadBigFloat (char *f) | 539 | float ReadBigFloat (unsigned char *f) |
540 | { | 540 | { |
541 | union | 541 | union |
542 | { | 542 | { |
diff --git a/apps/plugins/sdl/progs/quake/common.h b/apps/plugins/sdl/progs/quake/common.h index 8c6ab3a2dc..5f44b9fa43 100644 --- a/apps/plugins/sdl/progs/quake/common.h +++ b/apps/plugins/sdl/progs/quake/common.h | |||
@@ -96,21 +96,21 @@ extern int (*LittleLong) (int l); | |||
96 | extern float (*BigFloat) (float l); | 96 | extern float (*BigFloat) (float l); |
97 | extern float (*LittleFloat) (float l); | 97 | extern float (*LittleFloat) (float l); |
98 | 98 | ||
99 | #define LittleShortUnaligned(x) ReadLittleShort(((char*)(&(x)))) | 99 | #define LittleShortUnaligned(x) ReadLittleShort(((unsigned char*)(&(x)))) |
100 | #define BigShortUnaligned(x) ReadBigShort(((char*)&(x))) | 100 | #define BigShortUnaligned(x) ReadBigShort(((unsigned char*)&(x))) |
101 | #define LittleLongUnaligned(x) ReadLittleLong(((char*)&(x))) | 101 | #define LittleLongUnaligned(x) ReadLittleLong(((unsigned char*)&(x))) |
102 | #define BigLongUnaligned(x) ReadBigLong(((char*)&(x))) | 102 | #define BigLongUnaligned(x) ReadBigLong(((unsigned char*)&(x))) |
103 | #define LittleFloatUnaligned(x) ReadLittleFloat(((char*)&(x))) | 103 | #define LittleFloatUnaligned(x) ReadLittleFloat(((unsigned char*)&(x))) |
104 | #define BigFloatUnaligned(x) ReadBigFloat(((char*)&(x)) | 104 | #define BigFloatUnaligned(x) ReadBigFloat(((unsigned char*)&(x)) |
105 | 105 | ||
106 | 106 | ||
107 | // for unaligned | 107 | // for unaligned |
108 | short ReadBigShort (char *l); | 108 | short ReadBigShort (unsigned char *l); |
109 | short ReadLittleShort (char *l); | 109 | short ReadLittleShort (unsigned char *l); |
110 | int ReadBigLong (char *l); | 110 | int ReadBigLong (unsigned char *l); |
111 | int ReadLittleLong (char *l); | 111 | int ReadLittleLong (unsigned char *l); |
112 | float ReadBigFloat (char *l); | 112 | float ReadBigFloat (unsigned char *l); |
113 | float ReadLittleFloat (char *l); | 113 | float ReadLittleFloat (unsigned char *l); |
114 | 114 | ||
115 | //============================================================================ | 115 | //============================================================================ |
116 | 116 | ||
diff --git a/apps/plugins/sdl/progs/quake/model.c b/apps/plugins/sdl/progs/quake/model.c index 4c16c7f0f5..5ac6dc6cb2 100644 --- a/apps/plugins/sdl/progs/quake/model.c +++ b/apps/plugins/sdl/progs/quake/model.c | |||
@@ -1165,7 +1165,11 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer) | |||
1165 | mod_base = (byte *)header; | 1165 | mod_base = (byte *)header; |
1166 | 1166 | ||
1167 | for (i=0 ; i<sizeof(dheader_t)/4 ; i++) | 1167 | for (i=0 ; i<sizeof(dheader_t)/4 ; i++) |
1168 | ((int *)header)[i] = LittleLongUnaligned ( ((int *)header)[i]); | 1168 | { |
1169 | int before = ((int*)header)[i]; | ||
1170 | ((int *)header)[i] = LittleLongUnaligned ( ((int *)header) [i]); | ||
1171 | assert(((int*)header)[i] == before); // sanity check of our *Unaligned routines | ||
1172 | } | ||
1169 | 1173 | ||
1170 | // load into heap | 1174 | // load into heap |
1171 | 1175 | ||