Justin Yip。第四代香港人。好懶醒,自大又自卑。面前有珍饈百味,但總覺隔離飯香。
好記得闖王曾經講過,讀一個漂亮program,就如欣賞一首美麗的詩。 while (*s++ = *t++);
while (*s++ = *t++);
This entry was posted on 2008/03/18 於 14:15 and is filed under 電腦.
string copy. but can never make it works. i dunno why.
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); }
#include void main(){ char *s = malloc(10), *t = malloc(10); strcpy(s, "abcdefg"); char * tt = t; while (*t++ = *s++); printf("%s\n",tt); }
Amazing, but if two strings are overlap, then … you know what will happen.
有個問題我想問好耐,點解會叫佢做闖王﹖
Kane: eventually it will terminates~~ either t or s is overwritten, or the program segment is overwritten~~
Derek: 知唔知明末兵荒馬亂既時候同吳三桂最大仇口既係邊個?
@derek X 自成喎. 哈哈. 仲唔係闖王?
@Justin
Python :
v = s and 1 or 0 // v = s ? 1 : 0; // C
(command line) $python -c “import SimpleHTTPServer;SimpleHTTPServer.test()"
我扑有條prob, 你可以去諗下? 我太蠢諗唔到.
http://www.xanga.com/iidx_logan
我都記得, work 唔work 唔重要, 因為我都試過衰左… hahaa… 但係睇到真係嘩一聲…
lo 哥, 我頹寫左個solution, 你睇下岩唔岩
=.=
Log0: 我見呀。但未有心力諗。
你句python,好危險喎,可以好大既security loophole。
Winson: 我第一次睇完之後呆左好耐。
Derek: 我覺得好obvious喎呢個名。
你句C,都好危險喎,成個buffer overrun擺向度。我反而唔明句Python有乜問題。
你理佢危險唔危險,有啲野要做到野就得。你都唔會再用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. =)
Scorpio: 就好似樓下lo哥咁講,一講到安全就乜野美麗既景致都冇曬啦!
Lo: 唔單止係security,efficient都一樣。 我之前寫緊既system原本好美麗,之但係一去到個位我要improve佢既efficientcy 既時候,就搞到超樣衰。
在下方填入你的資料或按右方圖示以社群網站登入:
您的留言將使用 WordPress.com 帳號。 ( 登出 / 變更 )
您的留言將使用 Google+ 帳號。 ( 登出 / 變更 )
您的留言將使用 Twitter 帳號。 ( 登出 / 變更 )
您的留言將使用 Facebook 帳號。 ( 登出 / 變更 )
連結到 %s
透過電子郵件通知我後續回應。
2008/03/18 於 15:33
string copy. but can never make it works. i dunno why.
2008/03/18 於 15:48
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);
}
2008/03/18 於 20:01
Amazing, but if two strings are overlap,
then … you know what will happen.
2008/03/18 於 23:20
有個問題我想問好耐,點解會叫佢做闖王﹖
2008/03/18 於 23:50
Kane: eventually it will terminates~~ either t or s is overwritten, or the program segment is overwritten~~
Derek: 知唔知明末兵荒馬亂既時候同吳三桂最大仇口既係邊個?
2008/03/19 於 09:44
@derek
X 自成喎. 哈哈. 仲唔係闖王?
@Justin
Python :
v = s and 1 or 0 // v = s ? 1 : 0; // C
(command line)
$python -c “import SimpleHTTPServer;SimpleHTTPServer.test()"
我扑有條prob, 你可以去諗下? 我太蠢諗唔到.
2008/03/19 於 09:48
http://www.xanga.com/iidx_logan
2008/03/19 於 13:32
我都記得, work 唔work 唔重要, 因為我都試過衰左… hahaa…
但係睇到真係嘩一聲…
lo 哥, 我頹寫左個solution, 你睇下岩唔岩
2008/03/19 於 13:38
=.=
2008/03/19 於 17:10
Log0: 我見呀。但未有心力諗。
你句python,好危險喎,可以好大既security loophole。
Winson: 我第一次睇完之後呆左好耐。
Derek: 我覺得好obvious喎呢個名。
2008/03/19 於 21:49
你句C,都好危險喎,成個buffer overrun擺向度。我反而唔明句Python有乜問題。
2008/03/19 於 22:28
@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. =)
2008/03/24 於 20:20
Scorpio: 就好似樓下lo哥咁講,一講到安全就乜野美麗既景致都冇曬啦!
Lo: 唔單止係security,efficient都一樣。
我之前寫緊既system原本好美麗,之但係一去到個位我要improve佢既efficientcy 既時候,就搞到超樣衰。