Skip to content

Signed integer overflow #307

Closed
Closed
@lucasccordeiro

Description

@lucasccordeiro

CBMC provides "verification failed" for the following C program extracted from sv-benchmarks/c/signedintegeroverflow-regression/ConversionToSignedInt_true-no-overflow.c.i.

$cbmc ConversionToSignedInt_true-no-overflow.c --signed-overflow-check

#include <stdio.h>

int main() {
	// The literal of type long on the right-hand side is exactly INT_MAX+1 and will 
	// be converted to int.
	// Paragraph 6.3.1.3.3 of C11 says that if "[..] the new type is signed and the 
	// value cannot be represented in it; either the result is implementation-defined 
	// or an implementation-defined signal is raised."
	int x = 2147483648L;
	printf("%d\n", x);
	return 0;
}

** Results:
[main.overflow.1] arithmetic overflow on signed type conversion in (signed int)2147483648l: FAILURE

** 1 of 1 failed (1 iteration)
VERIFICATION FAILED

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions