From b154c9a5c49569e5c7caf57a9fcbc7da6c7fea15 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 27 Mar 2019 11:05:09 +0100 Subject: [PATCH] Eeschema: Force time stamp to 32 bits unsigned values, and make it tolerant to files using 64 bits values. define timestamp_t as uint32_t. This fix is adapted from master, commit 175a2bc0b (bug fix lp:1821476) --- eeschema/sch_legacy_plugin.cpp | 26 +++++++++++++------------- include/common.h | 5 +---- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index df49265808..88f24482cb 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -174,37 +174,37 @@ static int parseInt( FILE_LINE_READER& aReader, const char* aLine, const char** /** * Parse an ASCII hex integer string with possible leading whitespace into * a long integer and updates the pointer at \a aOutput if it is not NULL, just - * like "man strtol". + * like "man strtoll". * * @param aReader - The line reader used to generate exception throw information. * @param aLine - A pointer the current position in a string. * @param aOutput - The pointer to a string pointer to copy the string pointer position when * the parsing is complete. - * @return A valid integer value. + * @return A valid uint32_t value. * @throw IO_ERROR on an unexpected end of line. * @throw PARSE_ERROR if the parsed token is not a valid integer. */ -static unsigned long parseHex( FILE_LINE_READER& aReader, const char* aLine, +static uint32_t parseHex( LINE_READER& aReader, const char* aLine, const char** aOutput = NULL ) { if( !*aLine ) SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, aLine ); - unsigned long retv; + // Due to some issues between some files created by a 64 bits version and those + // created by a 32 bits version, we use here a temporary at least 64 bits storage: + unsigned long long retv; - // Clear errno before calling strtoul() in case some other crt call set it. + // Clear errno before calling strtoull() in case some other crt call set it. errno = 0; - retv = strtoul( aLine, (char**) aOutput, 16 ); + retv = strtoull( aLine, (char**) aOutput, 16 ); - // Make sure no error occurred when calling strtoul(). + // Make sure no error occurred when calling strtoull(). if( errno == ERANGE ) SCH_PARSE_ERROR( "invalid hexadecimal number", aReader, aLine ); // Strip off whitespace before the next token. if( aOutput ) { - // const char* next = aLine + strlen( token ); - const char* next = *aOutput; while( *next && isspace( *next ) ) @@ -213,7 +213,7 @@ static unsigned long parseHex( FILE_LINE_READER& aReader, const char* aLine, *aOutput = next; } - return retv; + return (uint32_t)retv; } @@ -1864,8 +1864,8 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent ) m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() ); // Generate unit number, convert and time stamp - m_out->Print( 0, "U %d %d %8.8lX\n", aComponent->GetUnit(), aComponent->GetConvert(), - (unsigned long)aComponent->GetTimeStamp() ); + m_out->Print( 0, "U %d %d %8.8X\n", aComponent->GetUnit(), aComponent->GetConvert(), + aComponent->GetTimeStamp() ); // Save the position m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y ); @@ -2011,7 +2011,7 @@ void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet ) aSheet->GetPosition().x, aSheet->GetPosition().y, aSheet->GetSize().x, aSheet->GetSize().y ); - m_out->Print( 0, "U %8.8lX\n", (unsigned long) aSheet->GetTimeStamp() ); + m_out->Print( 0, "U %8.8X\n", aSheet->GetTimeStamp() ); if( !aSheet->GetName().IsEmpty() ) m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(), diff --git a/include/common.h b/include/common.h index 62410d3676..780239c74e 100644 --- a/include/common.h +++ b/include/common.h @@ -60,11 +60,8 @@ class REPORTER; * Long term, this type might be renamed to something like unique_id_t * (and then rename all the methods from {Get,Set}TimeStamp() * to {Get,Set}Id()) ? - * - * The type should be at least 32 bit and simple to map via swig; swig does - * have issues with types such as 'int32_t', so we choose 'long'. */ -typedef long timestamp_t; +typedef uint32_t timestamp_t; // Flag for special keys