Support legacy timestamps with stripped leading zeros.

In old kicad_pcb files, the timestamp can have less than 8 symbols
if leading zeros are stripped.

For example: 0939A342 -> 939A342

(cherry picked from commit 472192f4b8)
This commit is contained in:
Alex Shvartzkop
2025-01-05 13:24:58 +05:00
parent dc88df7919
commit a678c9b03a
+11 -3
View File
@@ -37,6 +37,8 @@
#include <cctype>
#include <mutex>
#include <utility>
#include <stdlib.h>
#include <wx/log.h>
@@ -113,7 +115,7 @@ KIID::KIID( const std::string& aString ) :
m_uuid(),
m_cached_timestamp( 0 )
{
if( aString.length() == 8
if( !aString.empty() && aString.length() <= 8
&& std::all_of( aString.begin(), aString.end(),
[]( unsigned char c )
{
@@ -123,9 +125,15 @@ KIID::KIID( const std::string& aString ) :
// A legacy-timestamp-based UUID has only the last 4 octets filled in.
// Convert them individually to avoid stepping in the little-endian/big-endian
// doo-doo.
for( int i = 0; i < 4; ++i )
for( int i = 0; i < 4; i++ )
{
std::string octet = aString.substr( i * 2, 2 );
int start = static_cast<int>( aString.length() ) - 8 + i * 2;
int end = start + 2;
start = std::max( 0, start );
int len = std::max( 0, end - start );
std::string octet = aString.substr( start, len );
m_uuid.data[i + 12] = strtol( octet.data(), nullptr, 16 );
}