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
nilarg
Search
Matts966
September 24, 2019
Programming
0
170
nilarg
Prevent nil pointer dereferences when calling function in Go.
Matts966
September 24, 2019
Tweet
Share
More Decks by Matts966
See All by Matts966
OSS分散ベクトル検索エンジンValdと最新の取り組み
matts966
0
110
Grafana Dashboard as Code using Grafana Foundation SDK
matts966
3
250
Static Analysis in Go
matts966
0
3.1k
Phics
matts966
0
85
Other Decks in Programming
See All in Programming
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
230
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
720
文字コードの話
qnighy
44
17k
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
210
CSC307 Lecture 14
javiergs
PRO
0
470
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
390
Go1.26 go fixをプロダクトに適用して困ったこと
kurakura0916
0
370
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
420
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
130
TipKitTips
ktcryomm
0
160
エラーログのマスキングの仕組みづくりに役立ったASTの話
kumoichi
0
190
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
210
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
130
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Statistics for Hackers
jakevdp
799
230k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
A designer walks into a library…
pauljervisheath
210
24k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
860
Transcript
nil safety in Go nil safety in Go nil safety
in Go
nil safety? nil safety? Kotlin Go val user: User? =
getUser() val mail: String = user.Email // Compile Error val mail: String = user?.Email // OK var user *User mail := user.Email // Runtime Error if user != nil { mail := user.Email // OK } nil safety in Go
@tenntenn さんの より 『ソースコードを堪能せよ』 nil safety in Go
nil safety in Go
nil safety in Go
nilness nilness 関数内部のブロックを⾛査し、値がnil である か、nil でないか、unknow かを記録していく 同時にnil の値に対して危険な操作をしている箇 所を検出していく
SSA 、AST ともに関数を⼀つの単位として⾛査す る そのため他の関数呼び出しは別の処理が必要 であり、⾒逃されていた nil safety in Go
nilarg nilarg 全関数を⾛査して、nil になりうる型の引数に対 して、nil チェックせずに危険な操作をしていな いか確認 危険な操作を検知したら、該当の関数と引数を記 録 関数内部で関数を呼んでおり、その呼び出しが危
険な場合、再帰的に呼び出し元の関数も危険 そのため危険な関数リストを、リストの更新 がなくなるまで無限ループで更新 その後、実際に危険な関数をnil を引数として呼 び出している箇所を検出 nil safety in Go
Future Work Future Work LSP に組み込めば、関数がnil でpanic することを プログラマが意識できるのでは? 無名関数の変数など、静的解析で分からない部分
までは調べられない 引数が複数ある場合、偽陽性の可能性 go vet 本体に⼊れてもらいたい… SSA ⽣成周りにバグがありそうなのでデバッグ nil safety in Go
引数が複数ある場合、偽陽性の可 引数が複数ある場合、偽陽性の可 能性 能性 func doOptional(do bool, f func()) {
if do { f() } } nil safety in Go
links links @tenntenn さんの資料 つくったもの nilarg http://bit.ly/enjoysrc https://github.com/Matts966/refsafe https://github.com/Matts966/genelizer https://github.com/Matts966/nilarg
https://go- review.googlesource.com/c/tools/+/1953 nil safety in Go