Loose-Info.com
Last Update 2021/05/14
TOP - 各種テスト - gcc - 警告関連のオプション - フォーマット文字列関連のオプション - -Wno-format-contains-nul

-Wno-format-contains-nul
-Wformatが指定されている場合、ヌルバイトを含むフォーマット文字列について警告しない

テスト概要

-Wformatを指定した場合の、-Wno-format-contains-nulオプション有りと無しの出力を比較

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル


sample.c
#include <stdio.h> int main(void) { /* ヌルバイトが含まれる文字列 */ printf("ヌルバイト : \0 \n"); /* フォーマット文字列と引数の不一致 */ printf("n = %d\n", 1.23); return 0; }

動作テスト

-Wformatを指定した場合の、-Wno-format-contains-nulオプション有りと無しの出力を比較

-Wno-format-contains-nulオプション無しで実行
$ gcc -Wformat sample.c sample.c: In function ‘main’: sample.c:6:28: warning: embedded ‘\0’ in format [-Wformat-contains-nul] printf("ヌルバイト : \0 \n"); ヌルバイトに関する警告 ^~ sample.c:9:15: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=] printf("n = %d\n", 1.23); ~^ ~~~~ %f $

-Wno-format-contains-nulオプションを指定して実行
$ gcc -Wformat -Wno-format-contains-nul sample.c sample.c: In function ‘main’: sample.c:9:15: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=] printf("n = %d\n", 1.23); ~^ ~~~~ %f $ ヌルバイトに関する警告は出力されない