Skip to content
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

eval_rv_base: cast without torg when typeOf fails #1345

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/analyses/base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,11 @@ struct
Address (AD.map array_start (eval_lv ~ctx st lval))
| CastE (t, Const (CStr (x,e))) -> (* VD.top () *) eval_rv ~ctx st (Const (CStr (x,e))) (* TODO safe? *)
| CastE (t, exp) ->
let v = eval_rv ~ctx st exp in
VD.cast ~torg:(Cilfacade.typeOf exp) t v
(let v = eval_rv ~ctx st exp in
try
VD.cast ~torg:(Cilfacade.typeOf exp) t v
with Cilfacade.TypeOfError _ ->
VD.cast t v)
| SizeOf _
| Real _
| Imag _
Expand Down
11 changes: 11 additions & 0 deletions tests/regression/46-apron2/60-issue-1338.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SKIP PARAM: --set ana.activated[+] apron
#include <stdlib.h>
int main()
{
char *ptr = malloc(2);
char s = *(ptr+0)+0;

char *arr;
arr = malloc(8);
int tmp = (int)*(arr+0);
}