1. 程式人生 > >解決編譯時出現的警告:format string is not a string literal (potentially insecure)┊

解決編譯時出現的警告:format string is not a string literal (potentially insecure)┊

在Xcode 4.2(iOS 5)之前,我猜大家都和我一樣很喜歡下面的除錯輸出寫法:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 NSString *str = @"Attention"; // first warning NSLog(str); // second warning NSLog([str stringByAppendingFormat:@", %@", @"Xcode 4.2 do not support this format!"]); // third warning NSLog([NSString stringWithFormat:@
"%@, Xcode 4.2 do not support this format!", @"Attention"]); // fourth warning NSException *exception = [NSException exceptionWithName:@"Attention" reason:@"Xcode 4.2 do not support this format!" userInfo:nil]; NSLog(exception);



但是在Xcode 4.2(iOS 5)之後,貌似蘋果更新的編譯器,出了支援ARC的Apple LLVM compiler 3.0。然後我發現每次編譯,以前的這些輸出都會產生一個warning(警告,黃色三角形)。
在StackOverflow和iPhone Dev SDK查詢相關答案之後,發現在最新版的編譯器裡面NSLog為了安全,只接受格式化的字串,因為NSLog底層也是用printf來格式化輸出的。
所以上面的寫法都會給出警告,可以把上面的寫法修改為以下合法模式:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 NSString *str = @"Attention"; // first warning NSLog(str);                          // warning NSLog(@"%@", str);         // solution NSLog(str, nil);                   // solution // second warning NSLog([str stringByAppendingFormat:@
", %@", @"Xcode 4.2 do not support this format!"]);                         // warning NSLog(@"%@", [str stringByAppendingFormat:@", %@", @"Xcode 4.2 do not support this format!"]);         // solution NSLog([str stringByAppendingFormat:@", %@", @"Xcode 4.2 do not support this format!"], nil);                   //solution // third warning NSLog([NSString stringWithFormat:@"%@, Xcode 4.2 do not support this format!", @"Attention"]);             // warning NSLog(@"%@, Xcode 4.2 do not support this format!", @"Attention");                                                                // solution NSLog([NSString stringWithFormat:@

相關推薦

解決編譯出現警告format string is not a string literal (potentially insecure)┊

在Xcode 4.2(iOS 5)之前,我猜大家都和我一樣很喜歡下面的除錯輸出寫法: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 NSStrin

解決 Debug編譯警告warning LNK4099: 未找到 PDB“vc90.pdb”

警告:warning LNK4099: 未找到 PDB“vc90.pdb” 當多個Project是分開編譯的,主專案和子專案的pdb檔名相同(預設都是vc90.pdb或vc100.pdb)從而造成

Gradle打包出現警告編碼 GBK 的不可對映字元的問題

  對於gradle2.0以前的版本,在build.gradle的最後加上 tasks.withType(Compile) { options.encoding = "UTF-8" } 對於gradle2.0以後的版本,在build.gradle的最後加上 tasks.withTyp

關於JDBC連接數據庫出現的Public Key Retrieval is not allowed錯誤

三種 back 關於 reg host 出現 mysql命令 一次 增加 問題描述 最近在學習MyBatis框架,參考官方的文檔通過配置文件的方式已經實現了通過Configuration配置文件和mapper映射文件訪問mysql8數

idea警告Field injection is not recommended

1. 使用@Autowire注入時警告:Field injection is not recommended 2. 被警告程式碼: @Autowired private EduWorkInfoMapper eduWorkInfoMapper;

使用AOP處理註解出現error Type referred to is not an annotation type:xxx

今天本想通過AOP來處理添加註解的介面,結果丟擲了error Type referred to is not an annotation type:xxx(註解名)的異常,原來需要將註解作為處理方法的一個引數傳遞進來,並且引數名字要和@annotation中的名字一樣,不過

IDEA警告SQL dialect is not configured

Idea能自動給我們檢查拼接的sql語句的語法正確性,當然需要進行一定的配置。 在報警告的地方,單擊過後,按下快捷鍵Alt+Enter進入設定, 然後點選Generic,設定其dialect。 例如,

ajaxfileupload.js的報錯jQuery.handleError is not a function 解決辦法

handlerError只在jquery-1.4.2之前的版本中存在,jquery-1.4.2之後的版本中都沒有這個函數了。因此在jquery高階版本中將這個函式新增上 ,問題解決。 該js程式碼段可以加在jquer.js或者ajaxfileupload.js中。 ; (

ajaxFileUpload jQuery.handleError is not a function的解決方法

jQuery.handleError is not a function 報錯原因是: handlerError只在jquery-1.4.2之前的版本中存在,jquery-1.4.2之後的版本中都沒有

eclispe集成Scalas環境後,導入外部Spark包報錯object apache is not a member of package org

lisp ava ips package ack 網上 scala環境 sca ember 在Eclipse中集成scala環境後,發現導入的Spark包報錯,提示是:object apache is not a member of package org,網上說了一大推,

ndkbuild c++ string 'string' is not a member of 'std' 'string' was not declared in this scope

最近使用ndk時, #include <string> ndkbuild編譯後報錯:fatal error: string: No such file or directory #include <string.h> std::string 編

Could not parse UiSelector argument: 'XXX' is not a string

driver.find_element_by_android_uiautomator('new UiSelector().text("手機號/郵箱")').send_keys("12111") driver.find_element_by_android_uia

Could not parse UiSelector argument: 'XXX' is not a string

driver.find_element_by_android_uiautomator('new UiSelector().text("手機號/郵箱")').send_keys("12111") driver.find_element_by_android_uiautomator("new U

ecshop中使用ueditor(或其他特效)報錯b.replace is not a function/b[d].split is not a function

錯誤表現如下: 其實是transport.js檔案中的 Object.prototype.toJSONString = function () {} 引起的 刪除該函式會影響其他地方,那該怎麼辦

eclispe整合Scalas環境後,匯入外部Spark包報錯object apache is not a member of package org

在Eclipse中整合scala環境後,發現匯入的Spark包報錯,提示是:object apache is not a member of package org,網上說了一大推,其實問題很簡單; 解決辦法:在建立scala工程是,到了建立包的這一步是我們要選擇: 而不是建立java工程是的Java程式的

>Hibernate 報錯this project is not a myeclipse hibernate project . assuming hibernate 3 cap

問題 web 專案中 開啟 hibernate.cfg.xml 檔案時 提示:The project is not a myEclipse hibernate project。 並且:在 dbbrower中使用 hibernate reverse engineering 建立

出現“"cannot be resolved or is not a field",

出現“"cannot be resolved or is not a field",是因為當前java類的匯入不是當前專案的R檔案 ,而是匯入了Android.R檔案。 解決:找到對應報錯誤的類,刪除java程式碼中的”import Android.R“(在類匯入部分)。

檔案上傳報錯Current request is not a multipart request

  "error": "Internal Server Error",   "exception": "org.springframework.web.multipart.MultipartException",   "message": "Current request

平日小問題 (2)[Error] 'setprecision' is not a member of 'std'

#include <iostream> template <typename t> t sum(t x,t y) { return x+y; } int main()

Angular 懶載入報錯TypeError:undefined is not a function

前言     Angular日常採坑     在Angular中嘗試進行懶載入時,遇到以下錯誤: TypeError:undefined is not a function 導致原因     在Ap