为什么我的NSSMutableString可能不安全?
为什么我的NSMutableString
潜在不安全?我搜索了这个,但找不到任何东西。为什么我的NSSMutableString可能不安全?
int hour = [number intValue]/3600;
NSMutableString *time = [[NSMutableString alloc] initWithString:@""];
if (hour < 9) {
[time appendFormat:@"0"];
[time appendFormat:[NSMutableString stringWithFormat:@"%d:", hour]];
}
它有什么问题?这是我第一次看到这个。
更改此:
[time appendFormat:[NSMutableString stringWithFormat:@"%d:", hour]];
要这样:
[time appendFormat:@"%d:", hour];
的appendFormat
方法需要你通过与格式的字符串,而不是一个NSMutableString
。该截图显示了它:
这当然是答案。但你可能想解释一下。 :) –
非常感谢你,我知道现在哪里是错误的; ) –
这不回答这个问题要求在这里,但它看起来像所提供的代码试图彻底改造现有的格式字符串选项。
[NSMutableString stringWithFormat:@"%02d:", hour]
将打印一个两位数的整数值和前导零。
的确如此,但我认为这应该是一个评论,因为它没有回答这个问题。 – woz
我不确定你在问什么。如果你解释为什么你认为这个字符串“可能不安全”,这将有所帮助。 – Jonah
可能的重复[为什么我的字符串可能不安全在我的iOS应用程序?](http://stackoverflow.com/questions/9961363/why-is-my-string-potentially-unsecure-in-my-ios-application) –
也类似于:http://stackoverflow.com/questions/5428325/issue-with-code-format-string-is-not-a-string-literal – woz