]> git.ipfire.org Git - location/libloc.git/commitdiff
python: Do not check whether an integer is larger than 32 bit on 32 bit arches
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Nov 2020 15:37:22 +0000 (15:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Nov 2020 15:37:22 +0000 (15:37 +0000)
This cannot happen and generated a compiler warning

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/network.c

index b6e92fbc8f8fe7a8dc4603fd48a71ae8c91301ee..5b1369d6fd91352f680f7ee33fa677816392b19c 100644 (file)
@@ -17,6 +17,7 @@
 #include <Python.h>
 
 #include <errno.h>
+#include <limits.h>
 
 #include <loc/libloc.h>
 #include <loc/network.h>
@@ -133,11 +134,19 @@ static int Network_set_asn(NetworkObject* self, PyObject* value) {
        long int asn = PyLong_AsLong(value);
 
        // Check if the ASN is within the valid range
-       if (asn <= 0 || asn > UINT32_MAX) {
+       if (asn <= 0) {
                PyErr_Format(PyExc_ValueError, "Invalid ASN %ld", asn);
                return -1;
        }
 
+#if (__WORDSIZE > 32)
+       // Check whether the input was longer than 32 bit
+       if (asn > UINT32_MAX) {
+               PyErr_Format(PyExc_ValueError, "Invalid ASN %ld", asn);
+               return -1;
+       }
+#endif
+
        int r = loc_network_set_asn(self->network, asn);
        if (r)
                return -1;