In the program below, function dec
uses scanf
to read an arbitrary input from the user.
dec
is called from main
and depending on the input it returns 1 or 0 and accordingly an operation will be performed. However, the value analysis indicates that y
is always 0
, even after the call to scanf
. Why is that?
Note: the comments below apply to versions earlier than Frama-C 15 (Phosphorus, 20170501); in Frama-C 15, the Variadic plugin is enabled by default (and its short name is now
-variadic
).Solution
-va
) before running the value analysis (-val
), it will eliminate the warning and the program will behave as expected.Detailed explanation
Strictly speaking, Frama-C itself (the kernel) only does the parsing; it's up to the plug-ins themselves (e.g. Value/EVA) to evaluate the program.
From your description, I believe you must be using Value/EVA to analyze a program. I do not know exactly which version you are using, so I'll describe the behavior with Frama-C Silicon.
One limitation of ACSL (the specification language used by Frama-C) is that it is not currently possible to specify contracts for variadic functions such as
scanf
. Therefore, the specifications shipped with the Frama-C standard library are insufficient. You can notice this in the following program:Running
frama-c -val file.c
will output, among other things:That warning means that the specification is incorrect, which explains the odd behavior.
The solution in this case is to use the Variadic plug-in (
-va
, or-va-help
for more details), which will specialize variadic calls and add specifications to them, thus avoiding the warning and behaving as expected. Here's the resulting code (-print
) after running the Variadic plug-in on the example above:In this example,
scanf
was specialized toscanf_0
, with a proper ACSL annotation. Running EVA on this program will not emit any warnings and produce the expected output:Note: the GUI in Frama-C 14 (Silicon) does not allow the Variadic plug-in to be enabled (even after ticking it in the Analyses panel), so you must use the command-line in this case to obtain the expected result and avoid the warning. Starting from Frama-C 15 (Phosphorus, to be released in 2017), this won't be necessary: Variadic will be enabled by default and so your example would work from the start.