Revision | 1d49b488e92797649bc9c007556393098f671152 (tree) |
---|---|
Time | 2023-03-06 07:05:15 |
Author | Adam Kaminski <kaminskiadam9@gmai...> |
Commiter | Adam Kaminski |
Fixed a case of undefined behaviour caused by comparing two ColumnValue objects holding strings.
@@ -402,7 +402,18 @@ | ||
402 | 402 | return ( GetValue<float>( ) == Other.GetValue<float>( )); |
403 | 403 | |
404 | 404 | case COLUMNDATA_STRING: |
405 | - return ( strcmp( GetValue<const char *>( ), Other.GetValue<const char *>( )) == 0 ); | |
405 | + { | |
406 | + const char *pszString1 = GetValue<const char *>( ); | |
407 | + const char *pszString2 = Other.GetValue<const char *>( ); | |
408 | + | |
409 | + // [AK] If one of the strings is NULL, then return either true if | |
410 | + // both of them are NULL (i.e. pszString1 and pszString2 are equal), | |
411 | + // or false otherwise. | |
412 | + if (( pszString1 == NULL ) || ( pszString2 == NULL )) | |
413 | + return ( pszString1 == pszString2 ); | |
414 | + | |
415 | + return ( strcmp( pszString1, pszString2 ) == 0 ); | |
416 | + } | |
406 | 417 | |
407 | 418 | case COLUMNDATA_COLOR: |
408 | 419 | return ( GetValue<PalEntry>( ) == Other.GetValue<PalEntry>( )); |