Inverted arguments in scanf()

前端 未结 3 1851
既然无缘
既然无缘 2021-02-19 14:28

I was (quickly) writing some code and accidently inverted the arguments in scanf():

char i[] = \"ABC1\\t\";
scanf(i, \"%s\");

Comp

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 14:45

    Ha! I found it. Hitting gcc with the -Wformat=2 flag caught it.

    Posting the info for reference of others:

    Here's the list of flags I found

    -Wformat Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified...

    I had assumed -Wall had -Wformat in it, which it does, but the really important part about what I just found:

    -Wformat is included in -Wall. For more control over some aspects of format checking, the options -Wformat-y2k, -Wno-format-extra-args, -Wno-format-zero-length, -Wformat-nonliteral, -Wformat-security, and -Wformat=2 are available, but are not included in -Wall.

提交回复
热议问题