#26535: 用gets好像不安全


1234567weewee457@gmail.com (weewee4571234567)

學校 : 桃園市私立復旦高級中學
編號 : 92174
來源 : [114.43.44.160]
最後登入時間 :
2024-02-06 11:14:33
b968. K-I-S-S-I-N-G -- 板橋高中python教學題 | From: [118.166.23.238] | 發表日期 : 2021-08-12 15:36

不知道Xcode用gets為何會提示

warning: this program uses gets(), which is unsafe.

 
#26926: Re:用gets好像不安全


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
b968. K-I-S-S-I-N-G -- 板橋高中python教學題 | From: [27.246.4.142] | 發表日期 : 2021-09-02 15:57

不知道Xcode用gets為何會提示

warning: this program uses gets(), which is unsafe.


因為gets()無法限制字串長度,可能會造成overflow,scanf("%s", s)也是一樣,所以有人建議用fgets()。

可參考https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used

 
ZeroJudge Forum