Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
printf-args-num-ok?
Search
decafe09
February 24, 2018
Programming
170
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
プロダクト組織の変化 - PM Kansai #1 2026.01.22
decafe09
0
340
GoならわかるGIF
decafe09
0
370
よくあるWebサービスのAPIを作ったらいろいろ勉強になった話/WebApplicationAPITips
decafe09
1
400
goaを使ったAPI開発/api-development-with-goa
decafe09
0
2.1k
Other Decks in Programming
See All in Programming
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
150
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
110
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
470
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
160
Domain-Driven Transformation
hschwentner
2
2.3k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
350
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
140
SREの越境 / SRE Collaboration
y0hgi
2
300
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Ethics towards AI in product and experience design
skipperchong
2
420
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
620
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.8k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Being A Developer After 40
akosma
92
590k
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