|
Download cpp/cpp-ub-005.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.7 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-ub-005.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm@b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-ub-005.jsonl
-
curl -L -o cpp-ub-005.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/b5bf3ebebe22b46f4f78c2589a5bb814a44293a7/cpp/cpp-ub-005.jsonl
2.7 kB
| {"type": "session", "harness": "opencode", "id": "cpp-ub-005", "name": "C++ undefined behavior comprehensive patterns"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} | |
| {"type": "message", "message": {"role": "user", "content": "Comprehensive list of undefined behavior patterns in C++"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "**C++ Undefined Behavior Comprehensive Patterns:**\n\n**1. Signed Integer Overflow:**\n```cpp\nint x = INT_MAX;\nint y = x + 1; // UB!\n```\n\n**2. Unsigned Integer Wraparound:**\n```cpp\nunsigned x = 0;\nunsigned y = x - 1; // OK: wraps to UINT_MAX (defined)\n```\n\n**3. Null Pointer Dereference:**\n```cpp\nint* p = nullptr;\nint val = *p; // UB\n```\n\n**4. Out-of-Bounds Access:**\n```cpp\nint arr[10];\nint val = arr[10]; // UB (valid indices: 0-9)\n```\n\n**5. Use After Free:**\n```cpp\nint* p = new int(42);\ndelete p;\nint val = *p; // UB\n```\n\n**6. Double Free:**\n```cpp\nint* p = new int(42);\ndelete p;\ndelete p; // UB\n```\n\n**7. Data Races:**\n```cpp\n// Thread 1: // Thread 2:\nshared_var = 42; int x = shared_var; // UB!\n```\n\n**8. Strict Aliasing Violation:**\n```cpp\nfloat f = 3.14f;\nint* p = reinterpret_cast<int*>(&f);\nint val = *p; // UB\n```\n\n**9. Returning Reference to Local:**\n```cpp\nint& get_value() {\n int x = 42;\n return x; // UB!\n}\n```\n\n**10. Stack Overflow:**\n```cpp\nvoid infinite() {\n infinite(); // UB (eventually)\n}\n```\n\n**11. Invalid Shift:**\n```cpp\nint x = 1;\nint y = x << 32; // UB if int is 32 bits\nint z = x << -1; // UB\n```\n\n**12. Division by Zero:**\n```cpp\nint x = 0;\nint y = 10 / x; // UB\n```\n\n**13. Invalid Pointer Arithmetic:**\n```cpp\nint arr[10];\nint* p = arr + 20; // UB (past end)\nint* p2 = arr - 1; // UB (before begin)\n```\n\n**14. Alignment Violation:**\n```cpp\nchar buf[16];\nint* p = reinterpret_cast<int*>(buf + 1); // UB if not aligned\n*p = 42;\n```\n\n**15. Modifying String Literal:**\n```cpp\nchar* s = \"hello\";\ns[0] = 'H'; // UB\n```\n\n**16. Accessing Volatile Incorrectly:**\n```cpp\nvolatile int x = 0;\nint a = x;\nint b = x; // Compiler may optimize to single read\n```\n\n**17. Infinite Loops Without Side Effects (C++23 fix):**\n```cpp\n// C++17: UB\n// C++23: OK (P2809R3)\nwhile (true) { }\n```"}} | |