@@ -16,6 +16,7 @@ private class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlow
1616 hasGlobalName ( [
1717 // --- C library allocation
1818 "strdup" , // strdup(str)
19+ "strdupa" , // strdupa(str) - returns stack allocated buffer
1920 "wcsdup" , // wcsdup(str)
2021 "_strdup" , // _strdup(str)
2122 "_wcsdup" , // _wcsdup(str)
@@ -31,18 +32,20 @@ private class StrdupFunction extends AllocationFunction, ArrayFunction, DataFlow
3132 input .isParameterDeref ( 0 ) and
3233 output .isReturnValueDeref ( )
3334 }
35+
36+ override predicate requiresDealloc ( ) { not hasGlobalName ( "strdupa" ) }
3437}
3538
3639/**
3740 * A `strndup` style allocation function.
3841 */
3942private class StrndupFunction extends AllocationFunction , ArrayFunction , DataFlowFunction {
4043 StrndupFunction ( ) {
41- exists ( string name |
42- hasGlobalName ( name ) and
43- // --- C library allocation
44- name = "strndup " // strndup (str, maxlen)
45- )
44+ hasGlobalName ( [
45+ // -- C library allocation
46+ "strndup" , // strndup(str, maxlen)
47+ "strndupa " // strndupa (str, maxlen) -- returns stack allocated buffer
48+ ] )
4649 }
4750
4851 override predicate hasArrayInput ( int bufParam ) { bufParam = 0 }
@@ -56,4 +59,6 @@ private class StrndupFunction extends AllocationFunction, ArrayFunction, DataFlo
5659 ) and
5760 output .isReturnValueDeref ( )
5861 }
62+
63+ override predicate requiresDealloc ( ) { not hasGlobalName ( "strndupa" ) }
5964}
0 commit comments