Fix memOutOfBounds handling of negative pointer offsets#2017
Merged
Conversation
sim642
reviewed
May 7, 2026
Co-authored-by: Simmo Saan <simmo.saan@gmail.com>
michael-schwarz
left a comment
Member
There was a problem hiding this comment.
Other than the suggestion, LGTM!
| char *buf = malloc(4); | ||
| char *end; | ||
| end = buf + 4; //NOWARN | ||
| printf("%p", (void *) end); //NOWARN |
Member
There was a problem hiding this comment.
Suggested change
| printf("%p", (void *) end); //NOWARN | |
| printf("%p", (void *) end); //NOWARN | |
| printf("%c", *end); //WARN |
So we also see that we do indeed warn if this pointer is dereferenced.
Member
Author
There was a problem hiding this comment.
ha! it seems you just uncovered an unrelated unsoundness with this ;) I suggest we merge this as is and I will add this suggestion on another PR with an appropriate fix.
michael-schwarz
approved these changes
May 7, 2026
avsm
pushed a commit
to ocaml/opam-repository
that referenced
this pull request
Jun 15, 2026
CHANGES: * Add new may-happen-in-parallel analyses (goblint/analyzer#1805, goblint/analyzer#1865, goblint/analyzer#1913, goblint/analyzer#1928). * Add Open Verification Dashboard checks output (goblint/analyzer#1838, goblint/analyzer#1929). * Add negative bitwise shift warnings (goblint/analyzer#1637, goblint/analyzer#1989). * Add missing function declaration warnings (goblint/analyzer#1911). * Improve overflow warnings (goblint/analyzer#1894, goblint/analyzer#1895, goblint/analyzer#1896, goblint/analyzer#1905). * Fix spurious overflow checks (goblint/analyzer#1767, goblint/analyzer#1909, goblint/analyzer#1910, goblint/analyzer#1932, goblint/analyzer#2022). * Fix missing overflow and out-of-bounds checks (goblint/analyzer#1935, goblint/analyzer#2017, goblint/analyzer#2029). * Optimize base analysis domain using Patricia trees (goblint/analyzer#2002, goblint/analyzer#2015). * Optimize field offset calculations (goblint/analyzer#1964, goblint/analyzer#1973, goblint/analyzer#1974). * Optimize non-incremental top-down solver (goblint/analyzer#1566, goblint/analyzer#1972). * Add OCaml 5.5 support (goblint/analyzer#2006, goblint/analyzer#2010).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in
memOutOfBoundswhere before-start accesses were classified as safe when the offset was negative and precise enough underana.int.interval, i.e., the bug only manifested when interval domain was turned on. Withana.int.interval, Goblint can compute offsets precisely enough that negative-offset accesses no longer stay at top. This issue was found using the dashboard comparison between Goblint and Mopsa and was exposed by the SV-COMP tasklist-ext-properties/960521-1_1-1.i.memOutOfBoundscases intests/regression/74-invalid_deref.memOutOfBoundsto warn when the computed byte offset is negative, in addition to the existing past-the-end check.ptr_size_lt_offscomparison sites handleIntDomain.ArithmeticOnIntegerBotconsistently by falling back to the existing conservative “could not compare” behavior.(size - 1) < offsetsize < offset