ASAN error in stb_sprintf.h with MSVC

Open Beginner friendly
#5 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c
Domain
backend

Research direction

Start in stb_sprintf.h near the STBSP__ASAN macro around line 158, and check how the existing compiler conditional defines the AddressSanitizer exemption. Compare the MSVC __declspec(no_sanitize_address) spelling in the issue with the existing attribute. Done means MSVC builds with AddressSanitizer and the reported runtime error in stbsp__strlen_limited() is exempted.

Written by the indexing model from the issue text.

Description

(moved issue 1909 https://github.com/nothings/stb/issues/1909 from stb repo)

When compiling stb_sprintf.h with Microsoft MSVC, with Asan enabled, at runtime it will throw an error in stbsp__strlen_limited(). The function knowingly does evil things as a performance optimization. There is already a markup on the function to exempt it from AddressSanitizer checks.

But the markup macro isn't implemented for MSVC. Here is what I did to fix it

--- a/stb_sprintf.h
+++ b/stb_sprintf.h
@@ -158,6 +158,10 @@ PERFORMANCE vs MSVC 2008 32-/64-bit (GCC is even slower than MSVC):
  #if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__
   #define STBSP__ASAN __attribute__((__no_sanitize_address__))
  #endif
+#elif defined(_MSC_VER)
+  #if defined(__SANITIZE_ADDRESS__) && __SANITIZE_ADDRESS__
+    #define STBSP__ASAN __declspec(no_sanitize_address)
+  #endif
 #endif

Dominant language
C
Stars
18
Forks
5
Avg merge
1m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nothings/stb_sprintf

All issues in nothings/stb_sprintf

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.