Wformat-security C/C++ Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

warning: format string is not a string literal (potentially insecure) [-Wformat-security]

A printf-style function was given a variable as its format string.

Exact message you may see format string is not a string literalpotentially insecure format stringformat not a string literal and no format arguments
Seen on: C/C++ Clang GCC

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

  1. Use printf("%s", s)
  2. Use puts(s) or std::cout << s
  3. Mark wrapper functions with __attribute__((format(printf, 1, 2)))

Detailed fix by platform

GCC/Clang

  1. Keep -Wformat -Wformat-security enabled

Code examples

Format-string fix

c
printf(user_input);            // warning: format string is not a string literal
printf("%s", user_input);      // safe

How to diagnose

  1. Source — Where does the string come from?
  2. Literal — Can it be a constant?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

"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 (macOS)"x" can't be opened b…0x800704EC — 0x800704EC: This program is blocked by group policy (Windows Defender) (Windows)0x800704ECApple 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 (macOS)Apple could not verif…avc: denied — SELinux is preventing ... / avc: denied { read } for pid=... (permission denied despite correct permissions) (Linux)avc: deniedCredSSP encryption oracle remediation — Remote Desktop: An authentication error has occurred. The function requested is not supported. This could be due to CredSSP encryption oracle remediation (Windows)CredSSP encryption or…format expects argument of type — C: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=] (C/C++)format expects argume…gets — implicit declaration of function 'gets' / warning: the `gets' function is dangerous and should not be used (C/C++)getsis damaged and can’t be opened — macOS: “App” is damaged and can’t be opened. You should move it to the Trash. (macOS)is damaged and can’t …Wformat-s…

Explore the map of this error Full error map →

🧠 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.