Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
printf-args-num-ok?
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
decafe09
February 24, 2018
Programming
160
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
printf-args-num-ok?
goでprintfの引数の数をチェックするときの諸々について。
decafe09
February 24, 2018
More Decks by decafe09
See All by decafe09
GoならわかるGIF
decafe09
0
360
よくあるWebサービスのAPIを作ったらいろいろ勉強になった話/WebApplicationAPITips
decafe09
1
390
goaを使ったAPI開発/api-development-with-goa
decafe09
0
2.1k
Other Decks in Programming
See All in Programming
A2UI という光を覗いてみる
satohjohn
1
120
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
AIで効率化できた業務・日常
ochtum
0
120
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
140
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
1
640
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.2k
RTSPクライアントを自作してみた話
simotin13
0
520
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
120
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
20
6.4k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
530
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
250
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.4k
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
Typedesign – Prime Four
hannesfritz
42
3.1k
Everyday Curiosity
cassininazir
0
230
Designing Experiences People Love
moore
143
24k
Unsuck your backbone
ammeep
672
58k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
600
Designing for humans not robots
tammielis
254
26k
For a Future-Friendly Web
brad_frost
183
10k
Transcript
printf - args num ok? Umeda.go #3 2018 - 02
- 24 @decafe09
fmt.Printf fmt.Printf("%s", "moji")
fmt.Printf fmt.Printf("%s", "moji", "yobun")
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここで気づける moji%!(EXTRA string=yobun)
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここで気づける moji%!(EXTRA string=yobun) func main() { http.HandleFunc( "/xxx", func(w http.ResponseWriter, r *http.Request) { fmt.Printf("%s", "moji", "yobun") return }, ) http.ListenAndServe(":8080", nil) }
fmt.Printf $ go build # ここでは気づけない $ go run main.go
# ここでは気づけない $ curl localhost:8080/xxx # ここで気づける moji%!(EXTRA string=yobun)
go vet $ go vet ./main.go:6: Printf call needs 1
arg but has 2 args go vet ! curl " go vet CI go vet
go vet –printfuncs $ go vet –printfuncs=Infof ./main.go:6: Infof call
needs 1 arg but has 2 args func Infof(format string, a ...interface{}) (n int, err error) { return fmt.Printf(format, a...) }
go vet @ Go 1.10 $ go test ./main.go:6: Printf
call needs 1 arg but has 2 args go1.9.3 main.go:6: wrong number of args for format in Printf call: 1 needed but 2 args go1.10 main.go:6: Printf call needs 1 arg but has 2 args go test go vet go test -printfuncs
Humm... format := "%s" fmt.Printf(format, "moji", ”yobun")
Humm... $ go build # ここでは気づけない $ go vet #
ここでは気づけない $ go run main.go # ここで気づける moji%!(EXTRA string=yobun) http ! % # &$"%
Background API6=3.;?>/2,BW!:20/)O APIVK" C %!8>?4+?5JSAPIRFP XXNTL@YYNTLIEH XXYYEH
XX, YY O(&'!format!O(& %D 71? +<:20/GQ&72-/M%A format#xx,yy*9=-.;?U$
Thinking... "0(' ! 0(',1#%$ /0( $ !
+.)*format !format !&-...
Result func check(format string) error 1. format %! 2. format
message 3. format %! 4. %! func main() { format := "%s" err := check(format) if err != nil { panic(err) } fmt.Println(message(format)) } func message(format string) string { return fmt.Sprintf(format, "moji", "yobun") } func check(format string) error { pre := strings.Count(format, "%!") msg := message(format) post := strings.Count(msg, "%!") if post > pre { return errors.New("format error: " + msg) } return nil }
OK All errors begin with the string "%!" followed sometimes
by a single character (the verb) and end with a parenthesized description. https://golang.org/pkg/fmt/
Check $ go run main.go panic: format error: moji%!(EXTRA string=yobun)
Profile decafe09