Force time stamp to 32 bits unsigned values, and make it tolerant to files using 64 bits values.

define timestamp_t as uint32_t.

Fixes: lp:1821476
https://bugs.launchpad.net/kicad/+bug/1821476
This commit is contained in:
jean-pierre charras 2019-03-25 14:03:23 +01:00
parent aef369f4af
commit 175a2bc0b4
2 changed files with 14 additions and 17 deletions

View File

@ -174,37 +174,37 @@ static int parseInt( LINE_READER& aReader, const char* aLine, const char** aOutp
/** /**
* Parse an ASCII hex integer string with possible leading whitespace into * 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 * 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 aReader - The line reader used to generate exception throw information.
* @param aLine - A pointer the current position in a string. * @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 * @param aOutput - The pointer to a string pointer to copy the string pointer position when
* the parsing is complete. * 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 IO_ERROR on an unexpected end of line.
* @throw PARSE_ERROR if the parsed token is not a valid integer. * @throw PARSE_ERROR if the parsed token is not a valid integer.
*/ */
static unsigned long parseHex( LINE_READER& aReader, const char* aLine, static uint32_t parseHex( LINE_READER& aReader, const char* aLine,
const char** aOutput = NULL ) const char** aOutput = NULL )
{ {
if( !*aLine ) if( !*aLine )
SCH_PARSE_ERROR( _( "unexpected end of line" ), aReader, 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; 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 ) if( errno == ERANGE )
SCH_PARSE_ERROR( "invalid hexadecimal number", aReader, aLine ); SCH_PARSE_ERROR( "invalid hexadecimal number", aReader, aLine );
// Strip off whitespace before the next token. // Strip off whitespace before the next token.
if( aOutput ) if( aOutput )
{ {
// const char* next = aLine + strlen( token );
const char* next = *aOutput; const char* next = *aOutput;
while( *next && isspace( *next ) ) while( *next && isspace( *next ) )
@ -213,7 +213,7 @@ static unsigned long parseHex( LINE_READER& aReader, const char* aLine,
*aOutput = next; *aOutput = next;
} }
return retv; return (uint32_t)retv;
} }
@ -1860,8 +1860,8 @@ void SCH_LEGACY_PLUGIN::saveComponent( SCH_COMPONENT* aComponent )
m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() ); m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
// Generate unit number, convert and time stamp // Generate unit number, convert and time stamp
m_out->Print( 0, "U %d %d %8.8lX\n", aComponent->GetUnit(), aComponent->GetConvert(), m_out->Print( 0, "U %d %d %8.8X\n", aComponent->GetUnit(), aComponent->GetConvert(),
(unsigned long)aComponent->GetTimeStamp() ); aComponent->GetTimeStamp() );
// Save the position // Save the position
m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y ); m_out->Print( 0, "P %d %d\n", aComponent->GetPosition().x, aComponent->GetPosition().y );
@ -2007,7 +2007,7 @@ void SCH_LEGACY_PLUGIN::saveSheet( SCH_SHEET* aSheet )
aSheet->GetPosition().x, aSheet->GetPosition().y, aSheet->GetPosition().x, aSheet->GetPosition().y,
aSheet->GetSize().x, aSheet->GetSize().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() ) if( !aSheet->GetName().IsEmpty() )
m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(), m_out->Print( 0, "F0 %s %d\n", EscapedUTF8( aSheet->GetName() ).c_str(),

View File

@ -60,11 +60,8 @@ class REPORTER;
* Long term, this type might be renamed to something like unique_id_t * Long term, this type might be renamed to something like unique_id_t
* (and then rename all the methods from {Get,Set}TimeStamp() * (and then rename all the methods from {Get,Set}TimeStamp()
* to {Get,Set}Id()) ? * 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 // Flag for special keys