{"id":16337293,"url":"https://github.com/xophmeister/codeql-playground","last_synced_at":"2026-02-09T03:04:24.017Z","repository":{"id":251034559,"uuid":"836195741","full_name":"Xophmeister/codeql-playground","owner":"Xophmeister","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-01T12:42:20.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T03:48:40.585Z","etag":null,"topics":["codeql","playground","static-analysis"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Xophmeister.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-31T10:50:13.000Z","updated_at":"2024-08-01T12:42:30.000Z","dependencies_parsed_at":"2024-12-26T22:34:51.197Z","dependency_job_id":null,"html_url":"https://github.com/Xophmeister/codeql-playground","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"08f265e24f3899efdc57de9f8ed5e5a477f79136"},"previous_names":["xophmeister/codeql-playground"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Xophmeister/codeql-playground","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xophmeister%2Fcodeql-playground","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xophmeister%2Fcodeql-playground/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xophmeister%2Fcodeql-playground/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xophmeister%2Fcodeql-playground/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xophmeister","download_url":"https://codeload.github.com/Xophmeister/codeql-playground/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xophmeister%2Fcodeql-playground/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29255397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-09T01:52:29.835Z","status":"online","status_checked_at":"2026-02-09T02:00:09.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeql","playground","static-analysis"],"created_at":"2024-10-10T23:46:31.356Z","updated_at":"2026-02-09T03:04:23.989Z","avatar_url":"https://github.com/Xophmeister.png","language":"Makefile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeQL Playground\n\nLet's write some [dodgy C code](/ub.c) to see what\n[CodeQL](https://codeql.github.com), with the default C/C++ queries, can\ncatch.\n\n## Results\n\nCodeQL didn't catch anything :disappointed:\n\n### Comparison\n\nGCC's static analysis does a much better job:\n\n```console\n$ gcc -fanalyzer ub.c\nub.c: In function ‘main’:\nub.c:10:5: warning: dereference of NULL ‘buffer’ [CWE-476] [-Wanalyzer-null-dereference]\n   10 |     printf(\"%d\\n\", *buffer);\n      |     ^~~~~~~~~~~~~~~~~~~~~~~\n  ‘main’: events 1-5\n    |\n    |    6 |   int* buffer = (int*)malloc(size * sizeof(int));\n    |      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~\n    |      |                       |\n    |      |                       (1) allocated here\n    |    7 |\n    |    8 |   if (buffer == NULL) {\n    |      |      ~\n    |      |      |\n    |      |      (2) assuming ‘buffer’ is NULL\n    |      |      (3) following ‘true’ branch (when ‘buffer’ is NULL)...\n    |    9 |     /* Null-pointer dereference */\n    |   10 |     printf(\"%d\\n\", *buffer);\n    |      |     ~~~~~~~~~~~~~~~~~~~~~~~\n    |      |     |\n    |      |     (4) ...to here\n    |      |     (5) dereference of NULL ‘buffer’\n    |\nub.c:10:5: warning: use of uninitialized value ‘*buffer’ [CWE-457] [-Wanalyzer-use-of-uninitialized-value]\n   10 |     printf(\"%d\\n\", *buffer);\n      |     ^~~~~~~~~~~~~~~~~~~~~~~\n  ‘main’: events 1-4\n    |\n    |    6 |   int* buffer = (int*)malloc(size * sizeof(int));\n    |      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~\n    |      |                       |\n    |      |                       (1) region created on heap here\n    |    7 |\n    |    8 |   if (buffer == NULL) {\n    |      |      ~\n    |      |      |\n    |      |      (2) following ‘true’ branch (when ‘buffer’ is NULL)...\n    |    9 |     /* Null-pointer dereference */\n    |   10 |     printf(\"%d\\n\", *buffer);\n    |      |     ~~~~~~~~~~~~~~~~~~~~~~~\n    |      |     |\n    |      |     (3) ...to here\n    |      |     (4) use of uninitialized value ‘*buffer’ here\n    |\nub.c:22:5: warning: double-‘free’ of ‘buffer’ [CWE-415] [-Wanalyzer-double-free]\n   22 |     free(buffer);\n      |     ^~~~~~~~~~~~\n  ‘main’: events 1-12\n    |\n    |    6 |   int* buffer = (int*)malloc(size * sizeof(int));\n    |      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~\n    |      |                       |\n    |      |                       (1) allocated here\n    |    7 |\n    |    8 |   if (buffer == NULL) {\n    |      |      ~\n    |      |      |\n    |      |      (2) assuming ‘buffer’ is non-NULL\n    |      |      (3) following ‘false’ branch (when ‘buffer’ is non-NULL)...\n    |......\n    |   16 |   for (size_t i = 0; i \u003c= size; ++i) {\n    |      |               ~      ~~~~~~~~~\n    |      |               |        |\n    |      |               |        (5) following ‘true’ branch (when ‘i \u003c= size’)...\n    |      |               (4) ...to here\n    |   17 |     *(buffer + i) = (int)i;\n    |      |              ~\n    |      |              |\n    |      |              (6) ...to here\n    |......\n    |   21 |   for (size_t j = 0; j \u003c 2; ++j) {\n    |      |                      ~~~~~\n    |      |                        |\n    |      |                        (7) following ‘true’ branch (when ‘j \u003c= 1’)...\n    |      |                        (10) following ‘true’ branch (when ‘j \u003c= 1’)...\n    |   22 |     free(buffer);\n    |      |     ~~~~~~~~~~~~\n    |      |     |\n    |      |     (8) ...to here\n    |      |     (9) first ‘free’ here\n    |      |     (11) ...to here\n    |      |     (12) second ‘free’ here; first ‘free’ was at (9)\n    |\n```\n\nClang's `scan-build` can also detect the null dereference:\n\n```\nub.c:10:20: warning: Dereference of null pointer (loaded from variable 'buffer') [core.NullDereference]\n    printf(\"%d\\n\", *buffer);\n                   ^~~~~~~\n1 warning generated.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxophmeister%2Fcodeql-playground","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxophmeister%2Fcodeql-playground","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxophmeister%2Fcodeql-playground/lists"}