Fix erroneous hex parsing when opening legacy PCB files on MSVC.

e.g. "FFFF8007" does not fit into signed "long" type (4 bytes on MSVC),
so strtoul returns 0x7FFFFFFF and sets errno to EINVAL.


(cherry picked from commit 39978ab2e26c389240117f00556b7d53040824c7)

Co-authored-by: Alex Shvartzkop <dudesuchamazing@gmail.com>
This commit is contained in:
dsa-t 2025-08-05 23:14:41 +03:00
parent 4f59aaf2be
commit 39d2499cd7

View File

@ -97,7 +97,7 @@
typedef PCB_IO_KICAD_LEGACY::BIU BIU;
typedef unsigned LEG_MASK;
typedef uint32_t LEG_MASK;
#define FIRST_LAYER 0
#define FIRST_COPPER_LAYER 0
@ -404,10 +404,9 @@ static inline int intParse( const char* next, const char** out = nullptr )
* like "man strtol". I can use this without casting, and its name says
* what I am doing.
*/
static inline long hexParse( const char* next, const char** out = nullptr )
static inline uint32_t hexParse( const char* next, const char** out = nullptr )
{
// please just compile this and be quiet, hide casting ugliness:
return strtol( next, (char**) out, 16 );
return (uint32_t) strtoul( next, (char**) out, 16 );
}
@ -1140,7 +1139,7 @@ void PCB_IO_KICAD_LEGACY::loadSETUP()
// the old visibility control does not make sense in current Pcbnew version,
// and this code does not work.
#if 0
int visibleElements = hexParse( line + SZ( "VisibleElements" ) );
uint32_t visibleElements = hexParse( line + SZ( "VisibleElements" ) );
// Does not work: each old item should be tested one by one to set
// visibility of new item list
@ -1258,7 +1257,7 @@ void PCB_IO_KICAD_LEGACY::loadFOOTPRINT( FOOTPRINT* aFootprint )
int layer_num = intParse( data, &data );
PCB_LAYER_ID layer_id = leg_layer2new( m_cu_count, layer_num );
[[maybe_unused]] long edittime = hexParse( data, &data );
[[maybe_unused]] uint32_t edittime = hexParse( data, &data );
char* uuid = strtok_r( (char*) data, delims, (char**) &data );