warning: format string is not a string literal (potentially insecure) [-Wformat-security]
A printf-style function was given a variable as its format string.
format string is not a string literalpotentially insecure format stringformat not a string literal and no format arguments Meaning
If the string comes from user input it can contain %n or %s and read or write memory. The fix is to pass a literal format and the variable as an argument.
Common causes
printf(userString)syslog(LOG_ERR, msg)with a variable format- Logging wrappers forwarding a runtime format
⚡ Quick fix
- Use
printf("%s", s) - Use
puts(s)orstd::cout << s - Mark wrapper functions with
__attribute__((format(printf, 1, 2)))
Detailed fix by platform
GCC/Clang
- Keep
-Wformat -Wformat-securityenabled
Code examples
Format-string fix
printf(user_input); // warning: format string is not a string literal
printf("%s", user_input); // safeHow to diagnose
- Source — Where does the string come from?
- Literal — Can it be a constant?
- Wrapper — Format attribute?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- "x" can't be opened because it is from an unidentified developer macOS: “app” can’t be opened because it is from an unidentified developer
- 0x800704EC 0x800704EC: This program is blocked by group policy (Windows Defender)
- Apple could not verify "x" is free of malware macOS: “app” cannot be opened because Apple cannot check it for malicious software / Apple could not verify “app” is free of malware that may harm your Mac
Most viewed in C/C++
- Bus error C/C++: Bus error (core dumped) — SIGBUS from misaligned access or a bad memory-mapped file
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 2 Dec 2026