New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use-of-uninitialized-value in SCIPparamGetChar #68
Comments
cc @pfetsch do you have hints on what is happening here? Since this is about the SCIP memory management |
It could be helpful to know what version of SCIP this is, since the line numbers don't seem to match in the last release (8.0.4). Compiling with |
this is 8.0.4 scipoptsuite tarz.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68 53
00
Le mar. 14 nov. 2023 à 12:05, Stefan Vigerske ***@***.***> a
écrit :
… It could be helpful to know what version of SCIP this is, since the line
numbers don't seem to match in the last release (8.0.4).
Compiling with NOBLKBUFMEM=true (or -DBMS_NOBLOCKMEM -DSCIP_NOBUFFERMEM)
may also help to get more precise output, though in this case it seems
quite clear what this is about. It should be harmless, but I wonder why
this didn't happen more often.
—
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3NFIJ5WOVHTYF4QI4LYENF67AVCNFSM6AAAAAA7KS25KSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBZHE4TMNJVHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Is there a workaround ? I cannot turn off msan in our tests.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68 53
00
Le mar. 14 nov. 2023 à 12:36, Laurent Perron ***@***.***> a écrit :
… this is 8.0.4 scipoptsuite tarz.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68
53 00
Le mar. 14 nov. 2023 à 12:05, Stefan Vigerske ***@***.***>
a écrit :
> It could be helpful to know what version of SCIP this is, since the line
> numbers don't seem to match in the last release (8.0.4).
>
> Compiling with NOBLKBUFMEM=true (or -DBMS_NOBLOCKMEM -DSCIP_NOBUFFERMEM)
> may also help to get more precise output, though in this case it seems
> quite clear what this is about. It should be harmless, but I wonder why
> this didn't happen more often.
>
> —
> Reply to this email directly, view it on GitHub
> <#68 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACUPL3NFIJ5WOVHTYF4QI4LYENF67AVCNFSM6AAAAAA7KS25KSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBZHE4TMNJVHA>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
OK, I seem to have had mixed up line numbers. Does this change fixes it for you? --- a/src/scip/paramset.c
+++ b/src/scip/paramset.c
@@ -1147,6 +1147,7 @@ SCIP_RETCODE paramCreateChar(
(*param)->paramtype = SCIP_PARAMTYPE_CHAR;
(*param)->data.charparam.valueptr = valueptr;
(*param)->data.charparam.defaultvalue = defaultvalue;
+ (*param)->data.charparam.curvalue = defaultvalue;
if( allowedvalues != NULL )
{
SCIP_ALLOC( BMSduplicateMemoryArray(&(*param)->data.charparam.allowedvalues, allowedvalues, strlen(allowedvalues)+1) ); |
It does not. Is the init called ? |
Not sure which "init" you mean. The use-of-uninitialized-value is in return param->data.charparam.curvalue; It is called from My only other guess now is that a char is small and for some reason, it is reading more than the one |
I now see that this is about the first parameter created. So, do you actually get more than this one warning? Sure that after the proposed fix, the remaining warning is still about |
This is the only one I get (surprisingly as all params share the same structure). |
OK. --- a/src/scip/paramset.c
+++ b/src/scip/paramset.c
@@ -1147,6 +1147,8 @@ SCIP_RETCODE paramCreateChar(
(*param)->paramtype = SCIP_PARAMTYPE_CHAR;
(*param)->data.charparam.valueptr = valueptr;
(*param)->data.charparam.defaultvalue = defaultvalue;
+ if( valueptr != NULL )
+ *valueptr = defaultvalue;
if( allowedvalues != NULL )
{
SCIP_ALLOC( BMSduplicateMemoryArray(&(*param)->data.charparam.allowedvalues, allowedvalues, strlen(allowedvalues)+1) ); |
Good news, it works for char. ==3776419==WARNING: MemorySanitizer: use-of-uninitialized-value |
I don't think it crashes. It reads an uninitialized value. But it hardly does anything with it, that's why this is a harmless warning. The same fix as for |
I know. It is just crashing our tests.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68 53
00
Le mar. 14 nov. 2023 à 18:21, Stefan Vigerske ***@***.***> a
écrit :
… I don't think it crashes. It reads an uninitialized value. But it hardly
does anything with it, that's why this is a harmless warning.
The same fix as for paramCreateChar() would then need to go into the
other paramCreate*() functions.
—
Reply to this email directly, view it on GitHub
<#68 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUPL3KB77DA45W4UCKAPJ3YEOSCJAVCNFSM6AAAAAA7KS25KSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJQG42DENRVGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
If I fix all code paths, It still crashes in SCIPParamGetBool.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68 53
00
Le mar. 14 nov. 2023 à 18:22, Laurent Perron ***@***.***> a écrit :
… I know. It is just crashing our tests.
Laurent Perron | Operations Research | ***@***.*** | (33) 1 42 68
53 00
Le mar. 14 nov. 2023 à 18:21, Stefan Vigerske ***@***.***>
a écrit :
> I don't think it crashes. It reads an uninitialized value. But it hardly
> does anything with it, that's why this is a harmless warning.
>
> The same fix as for paramCreateChar() would then need to go into the
> other paramCreate*() functions.
>
> —
> Reply to this email directly, view it on GitHub
> <#68 (comment)>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACUPL3KB77DA45W4UCKAPJ3YEOSCJAVCNFSM6AAAAAA7KS25KSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJQG42DENRVGI>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Here is a more complete patch: --- a/src/scip/paramset.c
+++ b/src/scip/paramset.c
@@ -640,7 +640,7 @@ SCIP_RETCODE paramCopyString(
/* get value of source parameter and copy it to target parameter */
value = SCIPparamGetString(sourceparam);
- SCIP_CALL( SCIPparamSetString(targetparam, set, messagehdlr, value, TRUE) );
+ SCIP_CALL( SCIPparamSetString(targetparam, set, messagehdlr, value, FALSE, TRUE) );
return SCIP_OKAY;
}
@@ -1186,7 +1186,7 @@ SCIP_RETCODE paramCreateString(
SCIP_ALLOC( BMSduplicateMemoryArray(&(*param)->data.stringparam.defaultvalue, defaultvalue, strlen(defaultvalue)+1) );
(*param)->data.stringparam.curvalue = NULL;
- SCIP_CALL( SCIPparamSetString(*param, NULL, messagehdlr, defaultvalue, TRUE) );
+ SCIP_CALL( SCIPparamSetString(*param, NULL, messagehdlr, defaultvalue, TRUE, TRUE) );
return SCIP_OKAY;
}
@@ -1412,7 +1412,7 @@ SCIP_RETCODE paramParseString(
/* remove the quotes */
valuestr[len-1] = '\0';
valuestr++;
- SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, valuestr, TRUE) );
+ SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, valuestr, FALSE, TRUE) );
return SCIP_OKAY;
}
@@ -2135,7 +2135,7 @@ SCIP_RETCODE SCIPparamsetSetString(
}
/* set the parameter's current value */
- SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, value, TRUE) );
+ SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, value, FALSE, TRUE) );
return SCIP_OKAY;
}
@@ -4529,15 +4529,17 @@ SCIP_RETCODE SCIPparamSetBool(
/* check if the parameter is not fixed */
SCIP_CALL_QUIET( paramTestFixed(param, messagehdlr) );
+ if( !initialize )
+ oldvalue = SCIPparamGetBool(param);
+
/* set the parameter's current value */
- oldvalue = SCIPparamGetBool(param);
if( param->data.boolparam.valueptr != NULL )
*param->data.boolparam.valueptr = value;
else
param->data.boolparam.curvalue = value;
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initializing */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4589,15 +4591,17 @@ SCIP_RETCODE SCIPparamSetInt(
/* check if the parameter is not fixed */
SCIP_CALL_QUIET( paramTestFixed(param, messagehdlr) );
+ if( !initialize )
+ oldvalue = SCIPparamGetInt(param);
+
/* set the parameter's current value */
- oldvalue = SCIPparamGetInt(param);
if( param->data.intparam.valueptr != NULL )
*param->data.intparam.valueptr = value;
else
param->data.intparam.curvalue = value;
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initialization */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4649,15 +4653,17 @@ SCIP_RETCODE SCIPparamSetLongint(
/* check if the parameter is not fixed */
SCIP_CALL_QUIET( paramTestFixed(param, messagehdlr) );
+ if( !initialize )
+ oldvalue = SCIPparamGetLongint(param);
+
/* set the parameter's current value */
- oldvalue = SCIPparamGetLongint(param);
if( param->data.longintparam.valueptr != NULL )
*param->data.longintparam.valueptr = value;
else
param->data.longintparam.curvalue = value;
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initialization */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4711,15 +4717,17 @@ SCIP_RETCODE SCIPparamSetReal(
/* check if the parameter is not fixed */
SCIP_CALL_QUIET( paramTestFixed(param, messagehdlr) );
+ if( !initialize )
+ oldvalue = SCIPparamGetReal(param);
+
/* set the parameter's current value */
- oldvalue = SCIPparamGetReal(param);
if( param->data.realparam.valueptr != NULL )
*param->data.realparam.valueptr = value;
else
param->data.realparam.curvalue = value;
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initializing */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4770,15 +4778,17 @@ SCIP_RETCODE SCIPparamSetChar(
SCIP_CALL_QUIET( paramTestFixed(param, messagehdlr) );
+ if( !initialize )
+ oldvalue = SCIPparamGetChar(param);
+
/* set the parameter's current value */
- oldvalue = SCIPparamGetChar(param);
if( param->data.charparam.valueptr != NULL )
*param->data.charparam.valueptr = value;
else
param->data.charparam.curvalue = value;
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initializing */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4812,6 +4822,7 @@ SCIP_RETCODE SCIPparamSetString(
SCIP_SET* set, /**< global SCIP settings, or NULL if param change method should not be called */
SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
const char* value, /**< new value of the parameter */
+ SCIP_Bool initialize, /**< is this the initialization of the parameter? */
SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
)
{
@@ -4826,17 +4837,19 @@ SCIP_RETCODE SCIPparamSetString(
/* set the parameter's current value */
if( param->data.stringparam.valueptr != NULL )
{
- oldvalue = *param->data.stringparam.valueptr;
+ if( !initialize )
+ oldvalue = *param->data.stringparam.valueptr;
SCIP_ALLOC( BMSduplicateMemoryArray(param->data.stringparam.valueptr, value, strlen(value)+1) );
}
else
{
- oldvalue = param->data.stringparam.curvalue;
+ if( !initialize )
+ oldvalue = param->data.stringparam.curvalue;
SCIP_ALLOC( BMSduplicateMemoryArray(¶m->data.stringparam.curvalue, value, strlen(value)+1) );
}
- /* call the parameter's change information method */
- if( param->paramchgd != NULL && set != NULL )
+ /* call the parameter's change information method, unless initializing */
+ if( !initialize && param->paramchgd != NULL && set != NULL )
{
SCIP_RETCODE retcode;
@@ -4993,7 +5006,7 @@ SCIP_RETCODE SCIPparamSetToDefault(
break;
case SCIP_PARAMTYPE_STRING:
- SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, SCIPparamGetStringDefault(param), TRUE) );
+ SCIP_CALL( SCIPparamSetString(param, set, messagehdlr, SCIPparamGetStringDefault(param), FALSE, TRUE) );
break;
default:
diff --git a/src/scip/paramset.h b/src/scip/paramset.h
index 9674b46c76..d744e805fc 100644
--- a/src/scip/paramset.h
+++ b/src/scip/paramset.h
@@ -523,6 +523,7 @@ SCIP_RETCODE SCIPparamSetString(
SCIP_SET* set, /**< global SCIP settings, or NULL if param change method should not be called */
SCIP_MESSAGEHDLR* messagehdlr, /**< message handler */
const char* value, /**< new value of the parameter */
+ SCIP_Bool initialize, /**< is this the initialization of the parameter? */
SCIP_Bool quiet /**< should the parameter be set quiet (no output) */
);
diff --git a/src/scip/set.c b/src/scip/set.c
index 33dcdb06e5..caf3485cb0 100644
--- a/src/scip/set.c
+++ b/src/scip/set.c
@@ -3414,7 +3414,7 @@ SCIP_RETCODE SCIPsetChgStringParam(
assert(set != NULL);
assert(param != NULL);
- retcode = SCIPparamSetString(param, set, messagehdlr, value, TRUE);
+ retcode = SCIPparamSetString(param, set, messagehdlr, value, FALSE, TRUE);
if( retcode != SCIP_PARAMETERWRONGVAL )
{ If something still comes up, then we need the backtrace again. |
First tests seem ok. Thanks for the speedy patch. |
- the parameter value may not have been initialized, which raises uninitialized memory read warnings in memory checkers, e.g., valgrind - do no longer call the paramchg callback when creating a parameter, because, in case of a failure, we would try to reset the value to the old value, but now we have no longer read the old value - it also does not seem logical to claim a parameter change at the moment a parameter is created - fixes #68
We have this issue when using scip with memory sanitizer with scip called from OR-Tools MPSolver
where memory is allocated during:
The text was updated successfully, but these errors were encountered: