@@ -6,6 +6,15 @@ import cpp
6
6
import semmle.code.cpp.dataflow.DataFlow
7
7
import semmle.code.cpp.dataflow.TaintTracking
8
8
9
+ class StdNS extends Namespace {
10
+ StdNS ( ) {
11
+ this instanceof StdNamespace
12
+ or
13
+ this .isInline ( ) and
14
+ this .getParentNamespace ( ) instanceof StdNS
15
+ }
16
+ }
17
+
9
18
abstract class ContainerAccess extends VariableAccess {
10
19
abstract Variable getOwningContainer ( ) ;
11
20
}
@@ -168,11 +177,7 @@ class ContainerInvalidationOperation extends FunctionCall {
168
177
]
169
178
)
170
179
or
171
- exists ( FunctionCall fc |
172
- fc .getTarget ( ) .getNamespace ( ) .getName ( ) = "std" and
173
- fc .getTarget ( ) .getName ( ) in [ "swap" , "operator>>" , "getline" ] and
174
- this = fc
175
- )
180
+ this .getTarget ( ) .hasGlobalOrStdName ( [ "swap" , "operator>>" , "getline" ] )
176
181
)
177
182
)
178
183
}
@@ -195,7 +200,7 @@ class ContainerInvalidationOperation extends FunctionCall {
195
200
/** An iterator type in the `std` namespace. */
196
201
class StdIteratorType extends UserType {
197
202
StdIteratorType ( ) {
198
- getNamespace ( ) . getName ( ) = "std" and
203
+ this . getNamespace ( ) instanceof StdNS and
199
204
getSimpleName ( ) .matches ( "%_iterator" ) and
200
205
not getSimpleName ( ) .matches ( "const_%" )
201
206
}
@@ -247,16 +252,11 @@ class AdditiveOperatorFunctionCall extends FunctionCall {
247
252
*/
248
253
class STLContainer extends Class {
249
254
STLContainer ( ) {
250
- getNamespace ( ) .getName ( ) = "std" and
251
- getSimpleName ( ) in [
255
+ this .hasGlobalOrStdName ( [
252
256
"vector" , "list" , "deque" , "set" , "multiset" , "map" , "multimap" , "stack" , "queue" ,
253
257
"priority_queue" , "string" , "forward_list" , "unordered_set" , "unordered_multiset" ,
254
258
"unordered_map" , "unordered_multimap" , "valarray" , "string" , "basic_string"
255
- ]
256
- or
257
- getSimpleName ( ) = "string"
258
- or
259
- getSimpleName ( ) = "basic_string"
259
+ ] )
260
260
}
261
261
262
262
/**
@@ -291,7 +291,7 @@ class STLContainer extends Class {
291
291
IteratorSource getAConstIteratorEndFunctionCall ( ) { result = getACallTo ( "cend" ) }
292
292
293
293
IteratorSource getANonConstIteratorFunctionCall ( ) {
294
- result = getACallToAFunction ( ) and
294
+ // result = this. getACallToAFunction() and
295
295
result .getTarget ( ) .getType ( ) instanceof NonConstIteratorType
296
296
}
297
297
@@ -343,24 +343,24 @@ class STLContainerVariable extends Variable {
343
343
* to create this functionality.
344
344
*/
345
345
class IteratorRangeModel extends Function {
346
- IteratorRangeModel ( ) { hasQualifiedName ( "std" , "lexicographical_compare" ) }
346
+ IteratorRangeModel ( ) { this . hasGlobalOrStdName ( "lexicographical_compare" ) }
347
347
348
348
int getAnIndexOfAStartRange ( ) {
349
- ( hasQualifiedName ( "std" , "lexicographical_compare" ) and result = [ 0 , 1 ] )
349
+ ( this . hasGlobalOrStdName ( "lexicographical_compare" ) and result = [ 0 , 1 ] )
350
350
}
351
351
352
352
int getAnIndexOfAEndRange ( ) {
353
- ( hasQualifiedName ( "std" , "lexicographical_compare" ) and result = [ 2 , 3 ] )
353
+ ( this . hasGlobalOrStdName ( "lexicographical_compare" ) and result = [ 2 , 3 ] )
354
354
}
355
355
356
356
int getAnIteratorArgumentIndex ( ) {
357
- ( hasQualifiedName ( "std" , "lexicographical_compare" ) and result = [ 0 , 1 , 2 , 3 ] )
357
+ ( this . hasGlobalOrStdName ( "lexicographical_compare" ) and result = [ 0 , 1 , 2 , 3 ] )
358
358
}
359
359
360
360
predicate getAPairOfStartEndIndexes ( int start , int end ) {
361
- hasQualifiedName ( "std" , "lexicographical_compare" ) and start = 0 and end = 1
361
+ this . hasGlobalOrStdName ( "lexicographical_compare" ) and start = 0 and end = 1
362
362
or
363
- hasQualifiedName ( "std" , "lexicographical_compare" ) and start = 2 and end = 3
363
+ this . hasGlobalOrStdName ( "lexicographical_compare" ) and start = 2 and end = 3
364
364
}
365
365
}
366
366
@@ -378,7 +378,7 @@ class IteratorRangeFunctionCall extends FunctionCall {
378
378
count ( Expr e |
379
379
e = getAnArgument ( ) and
380
380
e .getType ( ) instanceof IteratorType and
381
- getTarget ( ) .getNamespace ( ) . getName ( ) = "std" and
381
+ getTarget ( ) .getNamespace ( ) instanceof StdNS and
382
382
not getTarget ( ) .getName ( ) in [ "operator==" , "operator!=" ]
383
383
) > 1
384
384
}
0 commit comments