{"id":18627484,"url":"https://github.com/yugr/sortcheckxx","last_synced_at":"2025-04-11T05:31:39.287Z","repository":{"id":41438792,"uuid":"451299037","full_name":"yugr/sortcheckxx","owner":"yugr","description":"Tool for detecting violations of ordering axioms in STL comparators","archived":false,"fork":false,"pushed_at":"2024-12-28T15:15:32.000Z","size":118,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T09:52:58.432Z","etag":null,"topics":["dynamic-analysis","program-analysis","qsort"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yugr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2022-01-24T03:08:29.000Z","updated_at":"2024-12-28T15:15:36.000Z","dependencies_parsed_at":"2024-12-20T20:37:58.917Z","dependency_job_id":null,"html_url":"https://github.com/yugr/sortcheckxx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2Fsortcheckxx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2Fsortcheckxx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2Fsortcheckxx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2Fsortcheckxx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yugr","download_url":"https://codeload.github.com/yugr/sortcheckxx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248347470,"owners_count":21088659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["dynamic-analysis","program-analysis","qsort"],"created_at":"2024-11-07T04:42:34.189Z","updated_at":"2025-04-11T05:31:39.259Z","avatar_url":"https://github.com/yugr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](http://img.shields.io/:license-MIT-blue.svg)](https://github.com/yugr/sortcheckxx/blob/master/LICENSE.txt)\n[![Build Status](https://github.com/yugr/sortcheckxx/actions/workflows/ci.yml/badge.svg)](https://github.com/yugr/sortcheckxx/actions)\n[![codecov](https://codecov.io/gh/yugr/sortcheckxx/branch/master/graph/badge.svg)](https://codecov.io/gh/yugr/sortcheckxx)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/yugr/sortcheckxx.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/yugr/sortcheckxx/alerts/)\n[![Coverity Scan](https://scan.coverity.com/projects/yugr-sortcheckxx/badge.svg)](https://scan.coverity.com/projects/yugr-sortcheckxx)\n\nSortChecker++ verifies that comparators in C++ APIs like `std::sort` or `std::binary_search`\nsatisfy the [Strict Weak Ordering](https://medium.com/@shiansu/strict-weak-ordering-and-the-c-stl-f7dcfa4d4e07)\naxioms.\nViolation of these axioms is undefined behavior and may lead to all sorts of runtime\nerrors including [aborts](https://stackoverflow.com/questions/2441045/bewildering-segfault-involving-stl-sort-algorithm)\n(also [here](https://stackoverflow.com/questions/46670734/erratic-behavior-of-gccs-stdsort-with-lambdas),\nsee [this answer](https://stackoverflow.com/a/24048654/2170527),\n[Qualys analysis](https://www.openwall.com/lists/oss-security/2024/01/30/7) and\n[my slides](https://github.com/yugr/CppRussia/blob/master/2023/EN.pdf) for explanations).\n\nSortChecker++ is an extension of [SortChecker](https://github.com/yugr/sortcheck) tool which does similar job to C sorting APIs.\n\nThe tool has been tested on LLVM 6.0 (Ubuntu 18.04), 10.0 (Ubuntu 20.04) and 14.0 (Ubuntu 22.04).\n\nList of found issues:\n* [Libosmium: Missing prepare\\_for\\_lookup in test\\_members\\_database.cpp](https://github.com/osmcode/libosmium/issues/351) (fixed)\n* [ZeroC Ice: Unsorted array in lookupKwd](https://github.com/zeroc-ice/ice/issues/1362) (fixed)\n* [GiNaC: Potential issue in comparator in test\\_antipode](https://www.ginac.de/pipermail/ginac-list/2022-June/002390.html) (fixed)\n* ArrayFire: Irreflexive comparator (already [fixed](https://github.com/arrayfire/arrayfire/commit/77181f1d9c860144554cd61e4de69b9dd82ccad9) in latest)\n* Giac: Non-asymmetric comparator in polynome\\_less (already [fixed](https://github.com/geogebra/giac/commit/efbde32d614aed9833903f93084f76bbf61cf418) in latest)\n\nNote that some (but not all!) errors found by Sortchecker++ can also be found via [`-D_LIBCPP_DEBUG_STRICT_WEAK_ORDERING_CHECK`](https://reviews.llvm.org/D150264).\n\n# How to build\n\nTo use, first install dependencies:\n```\n$ sudo apt install libclang-dev llvm-dev\n```\nand then build the tool\n```\n$ make clean all\n```\n\n# How to use\n\nSortChecker works by instrumenting the input file, i.e. inserting additional checking code into it.\nYou can run it manually via\n```\n$ SortChecker file.cpp -- $CXXFLAGS\n```\nthen compile via\n```\n$ g++ file.cpp $CXXFLAGS -Ipath/to/sortcheck.h\n```\n\nFinally run the resulting executable and it will report any errors e.g.\n```\n$ ./a.out\nsortcheck: file.cpp:23: non-asymmetric comparator at positions 1 and 0\n```\n(you'll probably want to combine this with some kind of regression\nor random/fuzz testing to achieve good coverage,\nalso see the `SORTCHECK_SHUFFLE` option below).\n\nYou could also use compiler wrappers in `scripts/` folder to combine instrumentation and compilation:\n```\n$ PATH=path/to/scripts:$PATH make clean all\n```\n\nInstrumented program may be controlled with environment variables:\n* `SORTCHECK_VERBOSE=N` - verbosity (`N` is an integer)\n* `SORTCHECK_SYSLOG=1` - dump messages to syslog (in addition to stderr)\n* `SORTCHECK_ABORT_ON_ERROR=1` - call `abort()` on detected error\n* `SORTCHECK_EXIT_CODE=N` - call `exit(CODE)` on detected error (`N` is an integer)\n* `SORTCHECK_OUTPUT=path/to/logfile` - write detected errors to file instead of stdout\n* `SORTCHECK_CHECKS=mask` - set which checks are enabled via bitmask\n  (e.g. `mask=0xfffe` would disable the generally uninteresting irreflexivity checks)\n* `SORTCHECK_SHUFFLE=val` - reshuffle containers before checking with given seed;\n  a value of `rand` will use random seed\n  (helps to find bugs which are not located at start of array)\n\n# Interpreting the error messages\n\ntbd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugr%2Fsortcheckxx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugr%2Fsortcheckxx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugr%2Fsortcheckxx/lists"}