From 2001d93b03dd2af62e341b91ab2bee9b92da03bc Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 11 Feb 2023 20:03:59 -0800 Subject: Check a string for NULL before calling strtoull --- alc/backends/pipewire.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 04cc38c7..7bde4b78 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -884,17 +884,18 @@ void NodeProxy::infoCallback(const pw_node_info *info) if(!nodeName || !*nodeName) nodeName = spa_dict_lookup(info->props, PW_KEY_NODE_NICK); if(!nodeName || !*nodeName) nodeName = devName; + uint64_t serial_id{info->id}; #ifdef PW_KEY_OBJECT_SERIAL - char *serial_end{}; - const char *serial_str{spa_dict_lookup(info->props, PW_KEY_OBJECT_SERIAL)}; - uint64_t serial_id{std::strtoull(serial_str, &serial_end, 0)}; - if(*serial_end != '\0' || errno == ERANGE) + if(const char *serial_str{spa_dict_lookup(info->props, PW_KEY_OBJECT_SERIAL)}) { - ERR("Unexpected object serial: %s\n", serial_str); - serial_id = info->id; + char *serial_end{}; + serial_id = std::strtoull(serial_str, &serial_end, 0); + if(*serial_end != '\0' || errno == ERANGE) + { + ERR("Unexpected object serial: %s\n", serial_str); + serial_id = info->id; + } } -#else - uint64_t serial_id{info->id}; #endif const char *form_factor{spa_dict_lookup(info->props, PW_KEY_DEVICE_FORM_FACTOR)}; -- cgit v1.2.3