C++: Prepare BufferWrite.qll for autoformat

The autoformatter cannot process these long end-of-line comments
properly when the line starts with `or`.
This commit is contained in:
Jonas Jensen
2019-09-05 12:26:47 +02:00
parent 29c83537b4
commit 44aca8a0f4

View File

@@ -109,26 +109,43 @@ class StrCopyBW extends BufferWriteCall
{ {
StrCopyBW() StrCopyBW()
{ {
exists(TopLevelFunction fn, string name | (fn = getTarget()) and (name = fn.getName()) and ( exists(TopLevelFunction fn, string name | fn = getTarget() and name = fn.getName() |
(name = "strcpy") // strcpy(dst, src) // strcpy(dst, src)
or (name = "wcscpy") // wcscpy(dst, src) name = "strcpy"
or (name = "_mbscpy") // _mbscpy(dst, src) or
or ( // wcscpy(dst, src)
( name = "wcscpy"
name = "strcpy_s" or // strcpy_s(dst, max_amount, src) or
name = "wcscpy_s" or // wcscpy_s(dst, max_amount, src) // _mbscpy(dst, src)
name = "_mbscpy_s" // _mbscpy_s(dst, max_amount, src) name = "_mbscpy"
) and or
fn.getNumberOfParameters() = 3 // exclude the 2-parameter template versions (
// that find the size of a fixed size destination buffer. name = "strcpy_s" or // strcpy_s(dst, max_amount, src)
) name = "wcscpy_s" or // wcscpy_s(dst, max_amount, src)
or (name = "strncpy") // strncpy(dst, src, max_amount) name = "_mbscpy_s" // _mbscpy_s(dst, max_amount, src)
or (name = "strncpy_l") // strncpy_l(dst, src, max_amount, locale) ) and
or (name = "wcsncpy") // wcsncpy(dst, src, max_amount) // exclude the 2-parameter template versions
or (name = "_wcsncpy_l") // _wcsncpy_l(dst, src, max_amount, locale) // that find the size of a fixed size destination buffer.
or (name = "_mbsncpy") // _mbsncpy(dst, src, max_amount) fn.getNumberOfParameters() = 3
or (name = "_mbsncpy_l") // _mbsncpy_l(dst, src, max_amount, locale) or
)) // strncpy(dst, src, max_amount)
name = "strncpy"
or
// strncpy_l(dst, src, max_amount, locale)
name = "strncpy_l"
or
// wcsncpy(dst, src, max_amount)
name = "wcsncpy"
or
// _wcsncpy_l(dst, src, max_amount, locale)
name = "_wcsncpy_l"
or
// _mbsncpy(dst, src, max_amount)
name = "_mbsncpy"
or
// _mbsncpy_l(dst, src, max_amount, locale)
name = "_mbsncpy_l"
)
} }
int getParamSize() int getParamSize()
@@ -248,19 +265,39 @@ class SprintfBW extends BufferWriteCall
{ {
SprintfBW() SprintfBW()
{ {
exists(TopLevelFunction fn, string name | (fn = getTarget()) and (name = fn.getName()) and ( exists(TopLevelFunction fn, string name | fn = getTarget() and name = fn.getName() |
// C sprintf variants /*
(name = "sprintf") // sprintf(dst, format, args...) * C sprintf variants
or (name = "vsprintf") // vsprintf(dst, format, va_list) */
or (name = "wsprintf") // wsprintf(dst, format, args...)
or (name = "vwsprintf") // vwsprintf(dst, format, va_list) // sprintf(dst, format, args...)
name = "sprintf"
// Microsoft sprintf variants or
or (name.regexpMatch("_sprintf_l")) // _sprintf_l(dst, format, locale, args...) // vsprintf(dst, format, va_list)
or (name.regexpMatch("_vsprintf_l")) // _vsprintf_l(dst, format, locale, va_list)) name = "vsprintf"
or (name.regexpMatch("__swprintf_l")) // __swprintf_l(dst, format, locale, args...) or
or (name.regexpMatch("__vswprintf_l")) // __vswprintf_l(dst, format, locale, va_list) // wsprintf(dst, format, args...)
)) name = "wsprintf"
or
// vwsprintf(dst, format, va_list)
name = "vwsprintf"
or
/*
* Microsoft sprintf variants
*/
// _sprintf_l(dst, format, locale, args...)
name.regexpMatch("_sprintf_l")
or
// _vsprintf_l(dst, format, locale, va_list))
name.regexpMatch("_vsprintf_l")
or
// __swprintf_l(dst, format, locale, args...)
name.regexpMatch("__swprintf_l")
or
// __vswprintf_l(dst, format, locale, va_list)
name.regexpMatch("__vswprintf_l")
)
} }
override Type getBufferType() override Type getBufferType()
@@ -307,24 +344,40 @@ class SnprintfBW extends BufferWriteCall
{ {
SnprintfBW() SnprintfBW()
{ {
exists(TopLevelFunction fn, string name | (fn = getTarget()) and (name = fn.getName()) and ( exists(TopLevelFunction fn, string name | fn = getTarget() and name = fn.getName() |
// C snprintf variants /*
(name = "snprintf") // snprintf(dst, max_amount, format, args...) * C snprintf variants
or (name = "vsnprintf") // vsnprintf(dst, max_amount, format, va_list) */
or (name = "swprintf") // swprintf(dst, max_amount, format, args...)
or (name = "vswprintf") // vswprintf(dst, max_amount, format, va_list) // snprintf(dst, max_amount, format, args...)
name = "snprintf"
// Microsoft snprintf variants or
or (name = "sprintf_s") // sprintf_s(dst, max_amount, format, locale, args...) // vsnprintf(dst, max_amount, format, va_list)
or (name = "vsprintf_s") // vsprintf_s(dst, max_amount, format, va_list) name = "vsnprintf"
or (name = "swprintf_s") // swprintf_s(dst, max_amount, format, args...) or
or (name = "vswprintf_s") // vswprintf_s(dst, max_amount, format, va_list) // swprintf(dst, max_amount, format, args...)
name = "swprintf"
// Microsoft snprintf variants with '_' or
or ( // vswprintf(dst, max_amount, format, va_list)
(name.regexpMatch("_v?sn?w?printf(_s)?(_p)?(_l)?")) name = "vswprintf"
and (not this instanceof SprintfBW) or
) /*
* Microsoft snprintf variants
*/
// sprintf_s(dst, max_amount, format, locale, args...)
name = "sprintf_s"
or
// vsprintf_s(dst, max_amount, format, va_list)
name = "vsprintf_s"
or
// swprintf_s(dst, max_amount, format, args...)
name = "swprintf_s"
or
// vswprintf_s(dst, max_amount, format, va_list)
name = "vswprintf_s"
or
// Microsoft snprintf variants with '_':
// _sprintf_s_l(dst, max_amount, format, locale, args...) // _sprintf_s_l(dst, max_amount, format, locale, args...)
// _swprintf_l(dst, max_amount, format, locale, args...) // _swprintf_l(dst, max_amount, format, locale, args...)
// _swprintf_s_l(dst, max_amount, format, locale, args...) // _swprintf_s_l(dst, max_amount, format, locale, args...)
@@ -343,7 +396,9 @@ class SnprintfBW extends BufferWriteCall
// _vsnprintf_l(dst, max_amount, format, locale, va_list) // _vsnprintf_l(dst, max_amount, format, locale, va_list)
// _vsnwprintf(dst, max_amount, format, va_list) // _vsnwprintf(dst, max_amount, format, va_list)
// _vsnwprintf_l(dst, max_amount, format, locale, va_list) // _vsnwprintf_l(dst, max_amount, format, locale, va_list)
)) name.regexpMatch("_v?sn?w?printf(_s)?(_p)?(_l)?") and
not this instanceof SprintfBW
)
} }
int getParamSize() int getParamSize()
@@ -405,11 +460,11 @@ class GetsBW extends BufferWriteCall
{ {
GetsBW() GetsBW()
{ {
exists(TopLevelFunction fn, string name | (fn = getTarget()) and (name = fn.getName()) and ( exists(TopLevelFunction fn, string name | fn = getTarget() and name = fn.getName() |
(name = "gets") // gets(dst) name = "gets" or // gets(dst)
or (name = "fgets") // fgets(dst, max_amount, src_stream) name = "fgets" or // fgets(dst, max_amount, src_stream)
or (name = "fgetws") // fgetws(dst, max_amount, src_stream) name = "fgetws" // fgetws(dst, max_amount, src_stream)
)) )
} }
int getParamSize() int getParamSize()
@@ -428,11 +483,11 @@ class GetsBW extends BufferWriteCall
override Expr getASource() override Expr getASource()
{ {
if exists(getArgument(2)) then ( if exists(getArgument(2))
result = getArgument(2) then result = getArgument(2)
) else ( else
result = this // the source is input inside the 'gets' call itself // the source is input inside the 'gets' call itself
) result = this
} }
override Expr getDest() override Expr getDest()