From 5dc6a712ef2cc383083220326354fc7aa960c798 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 11 Dec 2024 18:34:20 -0500 Subject: Avoid use of atoi() --- src/.clang-tidy | 1 - src/world.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/.clang-tidy b/src/.clang-tidy index 6fc648d..9cc7cdc 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -6,7 +6,6 @@ Checks: > -android-cloexec-fopen, -bugprone-narrowing-conversions, -cert-err33-c, - -cert-err34-c, -clang-analyzer-optin.core.EnumCastOutOfRange, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -clang-analyzer-valist.Uninitialized, diff --git a/src/world.c b/src/world.c index c23a34e..42e644c 100644 --- a/src/world.c +++ b/src/world.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -733,8 +734,14 @@ get_version(const LilvWorld* world, SordModel* model, const LilvNode* subject) LilvVersion version = {0, 0}; if (minor_node && micro_node) { - version.minor = atoi((const char*)sord_node_get_string(minor_node)); - version.micro = atoi((const char*)sord_node_get_string(micro_node)); + const char* const minor_str = (const char*)sord_node_get_string(minor_node); + const char* const micro_str = (const char*)sord_node_get_string(micro_node); + const long minor = strtol(minor_str, NULL, 10); + const long micro = strtol(micro_str, NULL, 10); + if (minor >= 0 && minor < INT_MAX && micro >= 0 && micro < INT_MAX) { + version.minor = (int)minor; + version.micro = (int)micro; + } } return version; -- cgit v1.2.1