Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b08ee949 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Merge branch 'issue128' into 'master'

Fix issue #128 by checking more carefully the sscanf error

Closes #128

See merge request solverstack/chameleon!451
parents 8b761f71 e3b5bb4d
No related branches found
No related tags found
1 merge request!451Fix issue #128 by checking more carefully the sscanf error
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -103,13 +104,24 @@ chameleon_env_on_off( char * str, int default_value ) { ...@@ -103,13 +104,24 @@ chameleon_env_on_off( char * str, int default_value ) {
} }
static inline int static inline int
chameleon_getenv_get_value_int(char * string, int default_value) { chameleon_getenv_get_value_int( char * string, int default_value ) {
extern int errno;
long int ret; long int ret;
char *str = chameleon_getenv(string); int rc;
if (str == NULL) return default_value; char *str = chameleon_getenv(string);
if ( sscanf( str, "%ld", &ret ) != 1 ) { if ( str == NULL ) {
perror("sscanf"); return default_value;
}
rc = sscanf( str, "%ld", &ret );
if ( rc != 1 ) {
if ( ( rc == EOF ) && ( errno != 0 ) ) {
perror( "chameleon_getenv_get_value_int(sscanf)" );
}
else {
fprintf( stderr, "%s: env variable %s expects an int value\n", __func__, string );
}
return default_value; return default_value;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment