Skip to content

fix: replace curl_error_map with switch to fix Static Initialization Order Fiasco#1296

Merged
COM8 merged 1 commit intolibcpr:masterfrom
MarkRakhmatov:fix-soif
Feb 15, 2026
Merged

fix: replace curl_error_map with switch to fix Static Initialization Order Fiasco#1296
COM8 merged 1 commit intolibcpr:masterfrom
MarkRakhmatov:fix-soif

Conversation

@MarkRakhmatov
Copy link
Contributor

@MarkRakhmatov MarkRakhmatov commented Feb 13, 2026

Closes #1295

Copy link
Member

@COM8 COM8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkRakhmatov thanks for contributing and fixing this! How did you debug the cause there? I also noticed this issue in the NuGet debug build but only when using msvc and I was unable identify it.

@COM8 COM8 merged commit d98f8d7 into libcpr:master Feb 15, 2026
34 of 37 checks passed
COM8 pushed a commit that referenced this pull request Feb 15, 2026
@MarkRakhmatov
Copy link
Contributor Author

@MarkRakhmatov thanks for contributing and fixing this! How did you debug the cause there? I also noticed this issue in the NuGet debug build but only when using msvc and I was unable identify it.

You are welcome :)

I saw this issue after refactoring tests and moving them from the main function to global test suites.
I debugged code with MSVC debug build and got read access violation inside unordered_map, so I started to go over the stack to see what object this is.

I know that such strange lifetime bugs usually occur when you access object that is not initialized yet, so first assumption was Static Initialization Order Fiasco

By the way, linter was suppressed for curl_error_map so for me it also was a sign that linter tried to warn about lifetime issues.
IMO it is good practice to specify exact rule that should be skipped and good reason, and generally avoid global objects (except for simple numeric constants like constexpr size_t gBlockSize = 1024;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Static initialization order fiasco in error.cpp curl_error_map

2 participants