Skip to content

Commit 242422b

Browse files
committed
Address review comments
1 parent 3baadfb commit 242422b

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

cpp/common/src/codingstandards/cpp/rules/readofuninitializedmemory/ReadOfUninitializedMemory.qll

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ class UninitializedVariable extends LocalVariable {
216216
VariableAccess getAUse() {
217217
result = this.getAnAccess() and
218218
(
219-
//count rvalue x as a use if not new int
219+
//count rvalue x (or *x) as a use if not new int
220220
result.isRValue() and
221-
not exists(PointerDereferenceExpr e | result = e.getAChild()) and
222221
not this.getInitializer().getExpr() instanceof NewNotInit
223222
or
224223
//count lvalue x as a use if used in *x and not new int
@@ -242,26 +241,6 @@ class UninitializedVariable extends LocalVariable {
242241
not result.getParent+() instanceof SizeofOperator
243242
}
244243

245-
// /**
246-
// * Gets an access of the this variable which is not used as an lvalue, and not used as an argument
247-
// * to an initialization function.
248-
// */
249-
// VariableAccess getAUse() {
250-
// result = this.getAnAccess() and
251-
// // Not used as an lvalue
252-
// not result = any(AssignExpr a).getLValue() and
253-
// //(result.isRValue() and not result.getType() instanceof PointerType and not this.getInitializer().getExpr() instanceof NewNotInit) and
254-
// // Not passed to another initialization function
255-
// not exists(Call c, int j | j = c.getTarget().(InitializationFunction).initializedParameter() |
256-
// result = c.getArgument(j).(AddressOfExpr).getOperand()
257-
// or
258-
// result.isRValue() and result = c.getArgument(j)
259-
// ) and
260-
// // Not a pointless read
261-
// not result = any(ExprStmt es).getExpr() and
262-
// // sizeof operators are not real uses
263-
// not result.getParent+() instanceof SizeofOperator
264-
// }
265244
/** Get a read of the variable that may occur while the variable is uninitialized. */
266245
VariableAccess getAnUnitializedUse() {
267246
exists(SubBasicBlock useSbb |

cpp/common/test/rules/readofuninitializedmemory/ReadOfUninitializedMemory.expected

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| test.cpp:211:8:211:9 | p1 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:206:8:206:9 | p1 | p1 |
1212
| test.cpp:217:8:217:9 | p2 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:214:8:214:9 | p2 | p2 |
1313
| test.cpp:220:10:220:11 | p2 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:214:8:214:9 | p2 | p2 |
14-
| test.cpp:229:7:229:8 | p4 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:227:8:227:9 | p4 | p4 |
15-
| test.cpp:234:14:234:15 | p5 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:233:8:233:9 | p5 | p5 |
16-
| test.cpp:238:8:238:9 | p6 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:236:8:236:9 | p6 | p6 |
14+
| test.cpp:228:7:228:8 | p4 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:226:8:226:9 | p4 | p4 |
15+
| test.cpp:230:8:230:9 | p4 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:226:8:226:9 | p4 | p4 |
16+
| test.cpp:233:14:233:15 | p5 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:232:8:232:9 | p5 | p5 |
17+
| test.cpp:237:8:237:9 | p6 | Local variable $@ is read here and may not be initialized on all paths. | test.cpp:235:8:235:9 | p6 | p6 |

cpp/common/test/rules/readofuninitializedmemory/test.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ void initialize(int *p) { *p = 0; }
201201
void extra_extra_test() {
202202
int *p0 = new int;
203203
use(p0); // COMPLIANT -- the pointer is valid
204-
use(*p0); // COMPLIANT[FALSE_POSITIVE] -- the pointer is valid
204+
use(*p0); // NON_COMPLIANT -- the pointer is valid but there is no value yet
205205

206206
int *p1 = new int;
207207
*p1 = 0; // COMPLIANT[FALSE_POSITIVE] -- this is not found bc this is not an
@@ -219,16 +219,15 @@ void extra_extra_test() {
219219
int *p3 = new int(1);
220220
*p3 = *p2; // NON_COMPLIANT -- the pointee of p2 has not been
221221
// initialized
222-
use(p3); // NON_COMPLIANT[FALSE_NEGATIVE] -- the pointee of p3 has been
223-
// overridden
222+
use(p3); // COMPLIANT -- the pointer is valid
224223
use(*p3); // NON_COMPLIANT[FALSE_NEGATIVE] -- the pointee of p3 has been
225224
// overridden
226225

227226
int *p4;
228227
p4 = new int;
229228
use(p4); // COMPLIANT[FALSE_POSITIVE] -- the pointer is valid but new int isnt
230229
// seen
231-
use(*p4); // COMPLIANT -- the value is not read and the pointer is valid
230+
use(*p4); // NON_COMPLIANT -- the value may be read
232231

233232
int *p5;
234233
initialize(p5); // NON_COMPLIANT

0 commit comments

Comments
 (0)