Skip to content

Instantly share code, notes, and snippets.

@nacho4d
Last active September 14, 2016 03:19
Show Gist options
  • Save nacho4d/ac102fcc62059ed9d30ba7dfa5d088ef to your computer and use it in GitHub Desktop.
Save nacho4d/ac102fcc62059ed9d30ba7dfa5d088ef to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("GIT_SSL_NO_VERIFY: %s\n", getenv("GIT_SSL_NO_VERIFY"));
if (getenv("GIT_SSL_NO_VERIFY"))
printf("evaluated as TRUE\n");
else
printf("evaluated as FALSE\n");
return EXIT_SUCCESS;
}
clang env.c
./a.out
# GIT_SSL_NO_VERIFY: (null)
# evaluated as FALSE
export GIT_SSL_NO_VERIFY=true; ./a.out
# GIT_SSL_NO_VERIFY: true
# evaluated as TRUE
export GIT_SSL_NO_VERIFY=false; ./a.out
# GIT_SSL_NO_VERIFY: false
# evaluated as TRUE
export GIT_SSL_NO_VERIFY; ./a.out
# GIT_SSL_NO_VERIFY: (null)
# evaluated as FALSE

exporting GIT_SSL_NO_VERIFY=true works as expected. Since there is a true, innocent people might think false is the oposite. They will be wrong and you will cause them problems.

Let's don't be lazy and use strcmp

char *gitSslNoVerify = getenv("GIT_SSL_NO_VERIFY");
if (gitSslNoVerify != NULL && strcmp(gitSslNoVerify, "true") == 0) {
    printf("really evaluated as TRUE\n");
} else {
    printf("really evaluated as FALSE\n");
}

Now it works as expected!

export GIT_SSL_NO_VERIFY; ./a.out
# GIT_SSL_NO_VERIFY: (null)
# really evaluated as FALSE

export GIT_SSL_NO_VERIFY=true; ./a.out
# GIT_SSL_NO_VERIFY: true
# really evaluated as TRUE

export GIT_SSL_NO_VERIFY=false; ./a.out
# GIT_SSL_NO_VERIFY: false
# really evaluated as FALSE

unset GIT_SSL_NO_VERIFY; ./a.out
# GIT_SSL_NO_VERIFY: (null)
# really evaluated as FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment