Tag Archives: pointer

Facebook 推出靜態分析工具:Facebook Infer

Facebook 推出了靜態分析工具 Facebook Infer,可以事先找出 AndroidiOS 上的 bug:Open-sourcing Facebook Infer: Identify bugs before you ship


Facebook Infer is a static analysis tool - if you give Infer some Objective-C, Java, or C code, it produces a list of potential bugs.

在 Android 上 (Java) 會找出的類型:

Infer reports null pointer exceptions and resource leaks in Android and Java code.

iOS 上則只找 memory leak:

In addition to this, it reports memory leak problems in iOS and C code.

比較特別的是,這個工具是用 OCaml 寫:

Infer is a static analysis tool for Java, Objective-C and C, written in OCaml.

JSON Patch...

與上篇一樣,都是在「Please. Don't Patch Like An Idiot.」這篇裡看到的:「JavaScript Object Notation (JSON) Patch」(RFC 6902)。

配合 JSON Pointer (RFC 6901) 的語法,下面的操作很清楚表示了想要做什麼:

    { "op": "test", "path": "/a/b/c", "value": "foo" },
    { "op": "remove", "path": "/a/b/c" },
    { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
    { "op": "replace", "path": "/a/b/c", "value": 42 },
    { "op": "move", "from": "/a/b/c", "path": "/a/b/d" },
    { "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }

再加上 HTTP header 裡的 If-Match 可以用來處理起始版本,test 也可以阻擋某些異常狀況,基本的都有了?接下來應該找 Canonical JSON 的方案,這樣可以直接拿 hash 的值當版本?

在 JSON 裡的 XPath...

在「Please. Don't Patch Like An Idiot.」這篇文章裡看到「JavaScript Object Notation (JSON) Pointer」(RFC 6901)。

類似 XML 的 XPath,JSON Pointer 可以查詢 JSON object。

比較特別是拿 ~ 這個符號當特殊字元,原本的 ~ 變成 ~0,而 / 變成 ~1,所以這個 JSON object:(取自 RFC 內的範例)

      "foo": ["bar", "baz"],
      "": 0,
      "a/b": 1,
      "c%d": 2,
      "e^f": 3,
      "g|h": 4,
      "i\\j": 5,
      "k\"l": 6,
      " ": 7,
      "m~n": 8

使用這些 JSON pointer 會得到後面這些結果:

    ""           // the whole document
    "/foo"       ["bar", "baz"]
    "/foo/0"     "bar"
    "/"          0
    "/a~1b"      1
    "/c%d"       2
    "/e^f"       3
    "/g|h"       4
    "/i\\j"      5
    "/k\"l"      6
    "/ "         7
    "/m~0n"      8