From 5dc6a712ef2cc383083220326354fc7aa960c798 Mon Sep 17 00:00:00 2001
From: David Robillard <d@drobilla.net>
Date: Wed, 11 Dec 2024 18:34:20 -0500
Subject: Avoid use of atoi()

---
 src/world.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/world.c')

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 <zix/tree.h>
 
 #include <assert.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -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