Skip to content

Commit

Permalink
cmake: version: enforce single byte limits
Browse files Browse the repository at this point in the history
Enforce the single byte size limits on the numeric fields in `VERSION`.

Signed-off-by: Jordan Yates <jordan@embeint.com>
  • Loading branch information
JordanYates authored and nashif committed Jun 24, 2024
1 parent 629858f commit 20348d6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmake/modules/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ foreach(type file IN ZIP_LISTS VERSION_TYPE VERSION_FILE)
string(REGEX MATCH "EXTRAVERSION = ([a-z0-9]*)" _ ${ver})
set(${type}_VERSION_EXTRA ${CMAKE_MATCH_1})

# Validate all version fields fit in a single byte
if(${type}_VERSION_MAJOR GREATER 255)
message(FATAL_ERROR "VERSION_MAJOR must be in the range 0-255 (Current ${${type}_VERSION_MAJOR})")
endif()
if(${type}_VERSION_MINOR GREATER 255)
message(FATAL_ERROR "VERSION_MINOR must be in the range 0-255 (Current ${${type}_VERSION_MINOR})")
endif()
if(${type}_PATCHLEVEL GREATER 255)
message(FATAL_ERROR "PATCHLEVEL must be in the range 0-255 (Current ${${type}_PATCHLEVEL})")
endif()
if(${type}_VERSION_TWEAK GREATER 255)
message(FATAL_ERROR "VERSION_TWEAK must be in the range 0-255 (Current ${${type}_VERSION_TWEAK})")
endif()

# Temporary convenience variables
set(${type}_VERSION_WITHOUT_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL})
set(${type}_VERSION_WITH_TWEAK ${${type}_VERSION_MAJOR}.${${type}_VERSION_MINOR}.${${type}_PATCHLEVEL}+${${type}_VERSION_TWEAK})
Expand Down

0 comments on commit 20348d6

Please sign in to comment.