Skip to content

Commit 6eba964

Browse files
committed
Handle gcc.StringCst on the right-hand-side of an assignment
1 parent dcb7b18 commit 6eba964

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

libcpychecker/absinterp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,8 @@ def eval_rvalue(self, expr, loc):
15491549
return ConcreteValue(expr.type, loc, expr.constant)
15501550
if isinstance(expr, gcc.RealCst):
15511551
return ConcreteValue(expr.type, loc, expr.constant)
1552+
if isinstance(expr, gcc.StringCst):
1553+
return AbstractValue(expr.type, loc)
15521554
if isinstance(expr, gcc.SsaName):
15531555
region = self.var_region(expr.var)
15541556
check_isinstance(region, Region)
@@ -2579,6 +2581,8 @@ def eval_rhs(self, stmt):
25792581
return self.eval_rvalue(rhs[0], stmt.loc)
25802582
elif stmt.exprcode == gcc.RealCst:
25812583
return self.eval_rvalue(rhs[0], stmt.loc)
2584+
elif stmt.exprcode == gcc.StringCst:
2585+
return self.eval_rvalue(rhs[0], stmt.loc)
25822586
elif stmt.exprcode == gcc.AddrExpr:
25832587
return self.eval_rvalue(rhs[0], stmt.loc)
25842588
elif stmt.exprcode == gcc.NopExpr:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2014 David Malcolm <dmalcolm@redhat.com>
3+
Copyright 2014 Red Hat, Inc.
4+
5+
This is free software: you can redistribute it and/or modify it
6+
under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful, but
11+
WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see
17+
<http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <Python.h>
21+
22+
char test_string(const char *src)
23+
{
24+
char buf[256]="";
25+
strncpy(buf, src, 256);
26+
return buf[0];
27+
}
28+
29+
/*
30+
PEP-7
31+
Local variables:
32+
c-basic-offset: 4
33+
indent-tabs-mode: nil
34+
End:
35+
*/
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2011 David Malcolm <dmalcolm@redhat.com>
3+
# Copyright 2011 Red Hat, Inc.
4+
#
5+
# This is free software: you can redistribute it and/or modify it
6+
# under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful, but
11+
# WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see
17+
# <http://www.gnu.org/licenses/>.
18+
19+
from libcpychecker import main
20+
21+
main(verify_refcounting=True,
22+
dump_traces=True)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Trace 0:
2+
Transitions:
3+
'returning'
4+
Return value:
5+
repr(): UnknownValue(gcctype=gcc.PointerType(dereference=<gcc.ArrayType object at 0xdeadbeef>), loc=gcc.Location(file='tests/cpychecker/absinterp/assignment-from-string-const/input.c', line=25))
6+
str(): unknown char[256] * from tests/cpychecker/absinterp/assignment-from-string-const/input.c:25
7+
Exception:
8+
(struct PyObject *)0 from tests/cpychecker/absinterp/assignment-from-string-const/input.c:23

0 commit comments

Comments
 (0)