/** * Verifies several NULL object-related properties * * @param pLogger Logger to log the message * @param pSmg SMG to check * @return True if pSmg is consistent w.r.t. this criteria. False otherwise. */ private static boolean verifyNullObjectCLangProperties(LogManager pLogger, CLangSMG pSmg) { // Verify that there is no NULL object in global scope for (SMGObject obj : pSmg.getGlobalObjects().values()) { if (!obj.notNull()) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent: null object in global object set [" + obj + "]"); return false; } } // Verify there is no more than one NULL object in the heap object set SMGObject firstNull = null; for (SMGObject obj : pSmg.getHeapObjects()) { if (!obj.notNull()) { if (firstNull != null) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent: second null object in heap object set [first=" + firstNull + ", second=" + obj + "]"); return false; } else { firstNull = obj; } } } // Verify there is no NULL object in the stack object set for (CLangStackFrame frame : pSmg.getStackFrames()) { for (SMGObject obj : frame.getAllObjects()) { if (!obj.notNull()) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent: null object in stack object set [" + obj + "]"); return false; } } } // Verify there is at least one NULL object if (firstNull == null) { pLogger.log(Level.SEVERE, "CLangSMG inconsistent: no null object"); return false; } return true; }
/** * Verify the stack name space: each record points to an appropriately labeled object * * @param pLogger Logger to log the message * @param pSmg the current smg * @return True if pSmg is consistent w.r.t. this criteria. False otherwise. */ private static boolean verifyStackNamespaces(LogManager pLogger, CLangSMG pSmg) { HashSet<SMGObject> stack_objects = new HashSet<>(); for (CLangStackFrame frame : pSmg.getStackFrames()) { for (SMGObject object : frame.getAllObjects()) { if (stack_objects.contains(object)) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent: object [" + object + "] present multiple times in the stack"); return false; } stack_objects.add(object); } } return true; }
/** * Verifies that global and stack object sets are disjunct * * @param pLogger Logger to log the message * @param pSmg SMG to check * @return True if pSmg is consistent w.r.t. this criteria. False otherwise. */ private static boolean verifyDisjunctGlobalAndStack(LogManager pLogger, CLangSMG pSmg) { Deque<CLangStackFrame> stack_frames = pSmg.getStackFrames(); Set<SMGObject> stack = new HashSet<>(); for (CLangStackFrame frame : stack_frames) { stack.addAll(frame.getAllObjects()); } Map<String, SMGRegion> globals = pSmg.getGlobalObjects(); boolean toReturn = Collections.disjoint(stack, globals.values()); if (!toReturn) { pLogger.log(Level.SEVERE, "CLangSMG inconsistent, global and stack objects are not disjoint"); } return toReturn; }
private void addStackItemSubgraph(CLangStackFrame pStackFrame, StringBuilder pSb, int pIndex) { String functionName = pStackFrame.getFunctionDeclaration().getName(); pSb.append(newLineWithOffset("subgraph cluster_stack_" + functionName + "{")); offset += 2; pSb.append(newLineWithOffset("fontcolor=blue;")); pSb.append( newLineWithOffset("label=\"" + pStackFrame.getFunctionDeclaration().toASTString() + "\";")); pSb.append( newLineWithOffset( smgScopeFrameAsDot(pStackFrame.getVariables(), String.valueOf(pIndex), functionName))); offset -= 2; pSb.append(newLineWithOffset("}")); }
/** * Verifies that heap and stack object sets are disjunct * * @param pLogger Logger to log the message * @param pSmg SMG to check * @return True if pSmg is consistent w.r.t. this criteria. False otherwise. */ private static boolean verifyDisjunctHeapAndStack(LogManager pLogger, CLangSMG pSmg) { Deque<CLangStackFrame> stack_frames = pSmg.getStackFrames(); Set<SMGObject> stack = new HashSet<>(); for (CLangStackFrame frame : stack_frames) { stack.addAll(frame.getAllObjects()); } Set<SMGObject> heap = pSmg.getHeapObjects(); boolean toReturn = Collections.disjoint(stack, heap); if (!toReturn) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent, heap and stack objects are not disjoint: " + Sets.intersection(stack, heap)); } return toReturn; }
/** * Verifies that heap, global and stack union is equal to the set of all objects * * @param pLogger Logger to log the message * @param pSmg SMG to check * @return True if pSmg is consistent w.r.t. this criteria. False otherwise. */ private static boolean verifyStackGlobalHeapUnion(LogManager pLogger, CLangSMG pSmg) { HashSet<SMGObject> object_union = new HashSet<>(); object_union.addAll(pSmg.getHeapObjects()); object_union.addAll(pSmg.getGlobalObjects().values()); for (CLangStackFrame frame : pSmg.getStackFrames()) { object_union.addAll(frame.getAllObjects()); } boolean toReturn = object_union.containsAll(pSmg.getObjects()) && pSmg.getObjects().containsAll(object_union); if (!toReturn) { pLogger.log( Level.SEVERE, "CLangSMG inconsistent: union of stack, heap and global object is not the same set as the set of SMG objects"); } return toReturn; }