PengZheng commented on code in PR #476: URL: https://github.com/apache/celix/pull/476#discussion_r1120141214
########## libs/utils/src/utils.c: ########## @@ -138,15 +172,32 @@ bool utils_isStringEmptyOrNull(const char * const str) { return empty; } -celix_status_t thread_equalsSelf(celix_thread_t thread, bool *equals) { - celix_status_t status = CELIX_SUCCESS; +char* celix_utils_writeOrCreateString(char* buffer, size_t bufferSize, const char* format, ...) { + va_list args; + va_start(args, format); + int written = vsnprintf(buffer, bufferSize, format, args); + va_end(args); + if (written < 0 || written >= bufferSize) { + //buffer to small, create new string + char* newStr = NULL; + va_start(args, format); + vasprintf(&newStr, format, args); Review Comment: Using `vasprintf` without checking return value is dangerous, since if -1 is returned the content of `newStr` is undefined. For various reasons why it may fail, see https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org