def RunRule(lexer, fullName, decl, contextStack, context): ext = lexer.filename[lexer.filename.rfind("."):] if not decl and ext != ".h" and context != None: upperBlock = contextStack.SigPeek() if upperBlock != None and upperBlock.type == "CLASS_BLOCK" and upperBlock.additional == "PRIVATE": return t1 = lexer.GetPrevTokenInType("STATIC", True) t2 = lexer.GetPrevTokenInTypeList(["SEMI", "RBRACE"], True) if t1 != None and (t2 == None or t1.lexpos > t2.lexpos): return t = lexer.GetCurToken() lexer.PushTokenIndex() t2 = lexer.GetPrevTokenInType("COMMENT") lexer.PopTokenIndex() lexer.PushTokenIndex() t3 = lexer.GetPrevTokenInTypeList(["SEMI", "PREPROCESSOR"], False, True) lexer.PopTokenIndex() if t2 != None and t2.additional == "DOXYGEN": if t3 == None or t.lexpos > t3.lexpos: return nsiqcppstyle_reporter.Error( t, __name__, "Doxygen Comment should be provided in front of function (%s) in impl file." % fullName)
def RunRule(lexer, contextStack) : t = lexer.GetCurToken() if t.type == "ID" : if t.value in unix_bufferoverflow_functions : t2 = lexer.PeekNextTokenSkipWhiteSpaceAndComment() if t2 != None and t2.type == "LPAREN" : t3 = lexer.PeekPrevTokenSkipWhiteSpaceAndComment() if t3 == None or t3.type != "PERIOD" : nsiqcppstyle_reporter.Error(t, __name__, "Do not use burfferoverflow risky function(%s)" % t.value)
def RunRule(lexer, contextStack): # Boost.Format, Folly.Format don't provide printf but if they do, # that can be handled by adding (or others) to whitelist whitelist = ["fmt"] blacklist = ["std", ""] # to catch ::printf t = lexer.GetCurToken() if t.type == "ID": if t.value in unix_bufferoverflow_functions: t2 = lexer.PeekNextTokenSkipWhiteSpaceAndComment() if t2 is not None and t2.type == "LPAREN": t3 = lexer.PeekPrevTokenSkipWhiteSpaceAndComment() # tribool state: safe, unsafe, unknown safe_alternative = False unsafe_alternative = False if t3 is None: # C style usage: flat out error unsafe_alternative = True elif t3.type == "PERIOD": # class member: the call is safe, impl might not be safe_alternative = True elif t3.type == "DOUBLECOLON": # check the namespace to classify as a dangerous # usage or a safe usage prev_namespace_token = lexer.GetPrevTokenInType( "ID", keepCur=True) if prev_namespace_token.value in whitelist: safe_alternative = True elif prev_namespace_token.value in blacklist: unsafe_alternative = True # elif unknown namespace => unknown safety if unsafe_alternative: nsiqcppstyle_reporter.Error(t, __name__, "Do not use bufferoverflow risky function(%s)" % t.value) elif not safe_alternative: nsiqcppstyle_reporter.Error(t, __name__, "Caution: Uknown imlementation of a bufferoverflow risky function(%s)" % t.value)
def RunRule(lexer, contextStack): t = lexer.GetCurToken() if t.type == "ID": if t.value in unix_bufferoverflow_functions: t2 = lexer.PeekNextTokenSkipWhiteSpaceAndComment() if t2 is not None and t2.type == "LPAREN": t3 = lexer.PeekPrevTokenSkipWhiteSpaceAndComment() # if :: comes first then we are not using dangerous C # functions, so we can get out if t3.type == "DOUBLECOLON": # check out the namespace that gives us this :: prev_namespace_token = lexer.GetPrevTokenInType("ID", keepCur=True) if prev_namespace_token.value != "std": return if t3 is None or t3.type != "PERIOD": nsiqcppstyle_reporter.Error(t, __name__, "Do not use burfferoverflow risky function(%s)" % t.value)