舊詩一首

2008/03/18

好記得闖王曾經講過,讀一個漂亮program,就如欣賞一首美麗的詩。

while (*s++ = *t++);

廣告

13 回應 to “舊詩一首”

  1. p Says:

    string copy. but can never make it works. i dunno why.

  2. Justin Says:

    try this:

    #include
    void main(){
    char *s = malloc(10), *t = malloc(10);
    strcpy(s, "abcdefg");
    char * tt = t;
    while (*t++ = *s++);
    printf("%s\n",tt);
    }

  3. Kane Says:

    Amazing, but if two strings are overlap,
    then … you know what will happen.

  4. Derek Says:

    有個問題我想問好耐,點解會叫佢做闖王﹖

  5. Justin Says:

    Kane: eventually it will terminates~~ either t or s is overwritten, or the program segment is overwritten~~

    Derek: 知唔知明末兵荒馬亂既時候同吳三桂最大仇口既係邊個?

  6. Log0 Says:

    @derek
    X 自成喎. 哈哈. 仲唔係闖王?

    @Justin

    Python :

    v = s and 1 or 0 // v = s ? 1 : 0; // C

    (command line)
    $python -c “import SimpleHTTPServer;SimpleHTTPServer.test()"

    我扑有條prob, 你可以去諗下? 我太蠢諗唔到.

  7. winson Says:

    我都記得, work 唔work 唔重要, 因為我都試過衰左… hahaa…
    但係睇到真係嘩一聲…

    lo 哥, 我頹寫左個solution, 你睇下岩唔岩

  8. Justin Says:

    Log0: 我見呀。但未有心力諗。

    你句python,好危險喎,可以好大既security loophole。

    Winson: 我第一次睇完之後呆左好耐。

    Derek: 我覺得好obvious喎呢個名。

  9. Scorpio Says:

    你句C,都好危險喎,成個buffer overrun擺向度。我反而唔明句Python有乜問題。

  10. Lo哥 Says:

    @Justin

    你理佢危險唔危險,有啲野要做到野就得。你都唔會再用unsafe strcpy喇?

    Security spoils elegance.
    There is almost a compromise between Security and a lot of things.

    Apparently, usability is one of them.
    So, discard Security?
    No.
    So, forfeit Usability?
    Ah, we will bypass security.

    有啲野都係知道佢好用就算. 又真係咁多人會顧及到喇.

    @winson:

    晏啲睇下,未有時間test. =)

  11. Justin Says:

    Scorpio: 就好似樓下lo哥咁講,一講到安全就乜野美麗既景致都冇曬啦!

    Lo: 唔單止係security,efficient都一樣。
    我之前寫緊既system原本好美麗,之但係一去到個位我要improve佢既efficientcy 既時候,就搞到超樣衰。


發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s

%d 位部落客按了讚: