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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
decafe09
February 24, 2018
Programming
0
160
printf-args-num-ok?
goでprintfの引数の数をチェックするときの諸々について。
decafe09
February 24, 2018
Tweet
Share
More Decks by decafe09
See All by decafe09
GoならわかるGIF
decafe09
0
350
よくあるWebサービスのAPIを作ったらいろいろ勉強になった話/WebApplicationAPITips
decafe09
1
380
goaを使ったAPI開発/api-development-with-goa
decafe09
0
2.1k
Other Decks in Programming
See All in Programming
AtCoder Conference 2025
shindannin
0
1k
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
140
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
CSC307 Lecture 07
javiergs
PRO
0
550
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
240
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
1
1.1k
組織で育むオブザーバビリティ
ryota_hnk
0
170
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
1
490
Accessibility Awareness
sabderemane
0
49
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
97
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
36k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
670
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
Thoughts on Productivity
jonyablonski
74
5k
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