Compare commits
	
		
			No commits in common. "master" and "cpplint/simple" have entirely different histories.
		
	
	
		
			master
			...
			cpplint/si
		
	
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| joj3_result.json | ||||
|  | @ -1,3 +1,3 @@ | |||
| # JOJ3 examples | ||||
| # cpplint sillycode | ||||
| 
 | ||||
| Check other branches. | ||||
| From <https://github.com/cpplint/cpplint/blob/develop/samples/silly-sample/src/sillycode.cpp>. | ||||
|  |  | |||
							
								
								
									
										59
									
								
								conf.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								conf.json
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| { | ||||
|   "stages": [ | ||||
|     { | ||||
|       "name": "cpplint", | ||||
|       "executor": { | ||||
|         "name": "sandbox", | ||||
|         "with": { | ||||
|           "default": { | ||||
|             "args": [ | ||||
|               "cpplint", | ||||
|               "--recursive", | ||||
|               "." | ||||
|             ], | ||||
|             "env": [ | ||||
|               "PATH=/usr/bin:/bin:/usr/local/bin" | ||||
|             ], | ||||
|             "cpuLimit": 10000000000, | ||||
|             "memoryLimit": 104857600, | ||||
|             "procLimit": 50, | ||||
|             "copyInDir": ".", | ||||
|             "copyOut": [ | ||||
|               "stdout", | ||||
|               "stderr" | ||||
|             ], | ||||
|             "stdin": { | ||||
|               "content": "" | ||||
|             }, | ||||
|             "stdout": { | ||||
|               "name": "stdout", | ||||
|               "max": 65536 | ||||
|             }, | ||||
|             "stderr": { | ||||
|               "name": "stderr", | ||||
|               "max": 65536 | ||||
|             } | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|       "parsers": [ | ||||
|         { | ||||
|           "name": "cpplint", | ||||
|           "with": { | ||||
|             "score": 0, | ||||
|             "comment": "check done", | ||||
|             "matches": [ | ||||
|               { | ||||
|                 "keywords": [ | ||||
|                   "whitespace", | ||||
|                   "legal" | ||||
|                 ], | ||||
|                 "score": 5 | ||||
|               } | ||||
|             ] | ||||
|           } | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										1
									
								
								expected.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								expected.json
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| [{"name":"cpplint","results":[{"score":-75,"comment":"### Test results summary\n\n1. `whitespace`: 14 occurrence(s), -70 point(s)\n2. `legal`: 1 occurrence(s), -5 point(s)\n"}],"force_quit":false}] | ||||
							
								
								
									
										144
									
								
								src/simple.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								src/simple.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,144 @@ | |||
| #include <climits> | ||||
| #include <cstdio> | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| 
 | ||||
| // Uninitialized member warning
 | ||||
| class BadClass { | ||||
|   int uninitMember; | ||||
| 
 | ||||
| public: | ||||
|   BadClass() {} // Missing member initialization
 | ||||
|   void print() { std::cout << uninitMember << std::endl; } | ||||
| }; | ||||
| 
 | ||||
| // Memory leak and resource management warnings
 | ||||
| void memoryLeaks() { | ||||
|   int *ptr = new int(42); | ||||
|   // Missing delete - memory leak
 | ||||
| 
 | ||||
|   int *array = new int[100]; | ||||
|   delete ptr; // Wrong deletion type for array
 | ||||
| 
 | ||||
|   // Double deletion
 | ||||
|   int *doubleDel = new int(5); | ||||
|   delete doubleDel; | ||||
|   delete doubleDel; | ||||
| } | ||||
| 
 | ||||
| // Null pointer dereferencing
 | ||||
| void nullPointerDereference(int *ptr) { | ||||
|   if (ptr == nullptr) { | ||||
|     *ptr = 42; // Dereferencing null pointer
 | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // Array bounds warnings
 | ||||
| void arrayBoundsIssues() { | ||||
|   int arr[5]; | ||||
|   for (int i = 0; i <= 5; i++) { // Off-by-one error
 | ||||
|     arr[i] = i; | ||||
|   } | ||||
| 
 | ||||
|   // Using uninitialized array
 | ||||
|   int uninitArr[10]; | ||||
|   int sum = 0; | ||||
|   for (int i = 0; i < 10; i++) { | ||||
|     sum += uninitArr[i]; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // Unused variables and dead code
 | ||||
| void unusedVariables() { | ||||
|   int unused = 42; | ||||
|   std::string neverUsed = "hello"; | ||||
| 
 | ||||
|   if (true) { | ||||
|     int unreachable = 10; | ||||
|   } else { | ||||
|     // Dead code
 | ||||
|     std::cout << "This will never execute" << std::endl; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // Integer overflow
 | ||||
| void integerOverflow() { | ||||
|   int max = INT_MAX; | ||||
|   max += 1; // Overflow
 | ||||
| 
 | ||||
|   unsigned int i = 0; | ||||
|   for (i = 10; i >= 0; i--) { // Infinite loop due to unsigned underflow
 | ||||
|     std::cout << i << std::endl; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // Resource leak in exception
 | ||||
| void resourceLeak() { | ||||
|   FILE *file = fopen("nonexistent.txt", "r"); | ||||
|   // Missing fclose and no exception handling
 | ||||
|   char buffer[100]; | ||||
|   fgets(buffer, 100, file); | ||||
| } | ||||
| 
 | ||||
| // Uninitialized variable usage
 | ||||
| void uninitializedVariables() { | ||||
|   int x; | ||||
|   if (x > 0) { // Using x without initialization
 | ||||
|     std::cout << "x is positive" << std::endl; | ||||
|   } | ||||
| 
 | ||||
|   bool flag; | ||||
|   while (flag) { // Using uninitialized flag
 | ||||
|     std::cout << "Loop" << std::endl; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| // Division by zero
 | ||||
| void divisionByZero(int divisor) { | ||||
|   int result = 100 / divisor; // No check for zero
 | ||||
| } | ||||
| 
 | ||||
| class Base { | ||||
| public: | ||||
|   void normalFunction() {} | ||||
|   virtual void virtualFunction() {} | ||||
| }; | ||||
| 
 | ||||
| class Derived : public Base { | ||||
| public: | ||||
|   void normalFunction() {}  // Hiding base class function
 | ||||
|   void virtualFunction() {} // Missing override keyword
 | ||||
| }; | ||||
| 
 | ||||
| int main() { | ||||
|   // Memory management issues
 | ||||
|   memoryLeaks(); | ||||
| 
 | ||||
|   // Null pointer issues
 | ||||
|   int *nullPtr = nullptr; | ||||
|   nullPointerDereference(nullPtr); | ||||
| 
 | ||||
|   // Array issues
 | ||||
|   arrayBoundsIssues(); | ||||
| 
 | ||||
|   // Dead code and unused variables
 | ||||
|   unusedVariables(); | ||||
| 
 | ||||
|   // Integer issues
 | ||||
|   integerOverflow(); | ||||
| 
 | ||||
|   // Resource management
 | ||||
|   resourceLeak(); | ||||
| 
 | ||||
|   // Uninitialized variables
 | ||||
|   uninitializedVariables(); | ||||
| 
 | ||||
|   // Division by zero
 | ||||
|   divisionByZero(0); | ||||
| 
 | ||||
|   // Object slicing
 | ||||
|   Derived derived; | ||||
|   Base base = derived; // Object slicing
 | ||||
| 
 | ||||
|   return 0; | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user