Fix WORD16 and WORD32 macros.
I made the mistake of using the same variable name _offset for the temporary variable in WORD16 and WORD32, and for the one in BYTE which the other two use as a subroutine - meaning that the declaration on the first line of BYTE read 'size_t _offset = _offset+3' or similar, in which the RHS _offset referred to the newly declared LHS one rather than to the one in the outer scope. WORD32 had the additional goof that I had declared its return-value accumulator variable as a 16- rather than 32-bit integer due to copy-and-paste error. Between those two mistakes - surely introduced at the last minute when I was doing code cleanup on this source base, because I know this function was working OK before then - I had completely broken the extraction of version strings from PE executables.
This commit is contained in:
parent
fe5eb01f9b
commit
0bc12e1c67
1 changed files with 11 additions and 11 deletions
22
version.c
22
version.c
|
@ -40,22 +40,22 @@ uint32_t MsiGetFileVersionW(const char16_t *filename,
|
||||||
unsigned char *map = (unsigned char *)mapv;
|
unsigned char *map = (unsigned char *)mapv;
|
||||||
|
|
||||||
#define BYTE(offset) ({ \
|
#define BYTE(offset) ({ \
|
||||||
size_t _offset = (offset); \
|
size_t _boffset = (offset); \
|
||||||
if (_offset >= fsize) goto cleanup; /* outside file bounds */ \
|
if (_boffset >= fsize) goto cleanup; /* outside file bounds */ \
|
||||||
map[_offset]; \
|
map[_boffset]; \
|
||||||
})
|
})
|
||||||
#define WORD16(offset) ({ \
|
#define WORD16(offset) ({ \
|
||||||
size_t _offset = (offset); \
|
size_t _woffset = (offset); \
|
||||||
uint16_t toret = BYTE(_offset+1); \
|
uint16_t toret = BYTE(_woffset+1); \
|
||||||
toret = (toret << 8) | BYTE(_offset+0); \
|
toret = (toret << 8) | BYTE(_woffset+0); \
|
||||||
toret; \
|
toret; \
|
||||||
})
|
})
|
||||||
#define WORD32(offset) ({ \
|
#define WORD32(offset) ({ \
|
||||||
size_t _offset = (offset); \
|
size_t _doffset = (offset); \
|
||||||
uint16_t toret = BYTE(_offset+3); \
|
uint32_t toret = BYTE(_doffset+3); \
|
||||||
toret = (toret << 8) | BYTE(_offset+2); \
|
toret = (toret << 8) | BYTE(_doffset+2); \
|
||||||
toret = (toret << 8) | BYTE(_offset+1); \
|
toret = (toret << 8) | BYTE(_doffset+1); \
|
||||||
toret = (toret << 8) | BYTE(_offset+0); \
|
toret = (toret << 8) | BYTE(_doffset+0); \
|
||||||
toret; \
|
toret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue