awslabs / aws-c-common

Core c99 package for AWS SDK for C. Includes cross-platform primitives, configuration, data structures, and error handling.
Apache License 2.0
262 stars 159 forks source link

Fix out variable in cmake sanitizer module #1134

Closed sfod closed 4 months ago

sfod commented 4 months ago

Issue #, if available:

The aws_check_sanitizer cmake function incorrectly handles the out parameter. The issue is with if(NOT ${ARGN}) check.

When an extra parameter is passed to the function (e.g., aws_check_sanitizer("thread" CUSTOM_OUT_VAR)), if(NOT ${ARGN}) checks the value of this extra parameter. This means that ${CUSTOM_OUT_VAR} will be used as out variable only if it's undefined/false:

aws_check_sanitizer("thread" CUSTOM_OUT_VAR)  # sets ${CUSTOM_OUT_VAR} to 1
aws_check_sanitizer("thread" CUSTOM_OUT_VAR)  # the second call sets ${HAS_SANITIZER_thread} to 1

When no extra parameter is passed (e.g., aws_check_sanitizer("thread")), this check essentially transforms to if(NOT). Which looks kind of weird, but in practice works fine.

Description of changes:

Check for the number of passed parameter to determine which variable to use as out parameter.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.