2014-05-19 93 views
-3
if (srcbloc == NULL) { 
    fprintf(stderr, "warning!: memrip source is null!\n"); 
    exit(1); 
} 
if (destbloc == NULL) { 
    destbloc = malloc(len); 
} 
if (srcbloc == destbloc) { 
    fprintf(stderr, "warning!: srcbloc = destbloc\n"); 
    exit(1); 
} 
if (offset < 0) { 
    fprintf(stderr, "warning!: offset = %i\n", offset); 
} 
if (len < 0) { 
    fprintf(stderr, "warning!: len = %i\n", len); 
} 

我想知道是否所有的if語句都會在這個程序運行時被測試嗎?如果聲明流程連續如下

+2

您是否嘗試過運行代碼以找出? – Wyzard

+0

您是否嘗試過使用某些調試日誌記錄? – ScottMcGready

+0

我們絕對沒有辦法讓沒有上下文的人知道被檢查的價值。 – ScottMcGready

回答

1

鑑於你的代碼

if (srcbloc == NULL) { /* <-- if this block is entered then, */ 
    fprintf(stderr, "warning!: memrip source is null!\n"); 
    exit(1); /* <-- Program will exit */ 
} 
if (destbloc == NULL) { /* <-- Allocate destbloc of len length. */ 
    destbloc = malloc(len); 
} 
if (srcbloc == destbloc) { /* <-- if this block is entered then, */ 
    fprintf(stderr, "warning!: srcbloc = destbloc\n"); 
    exit(1); /* <-- Program will exit */ 
} 
if (offset < 0) { 
    fprintf(stderr, "warning!: offset = %i\n", offset); 
} 
if (len < 0) { 
    fprintf(stderr, "warning!: len = %i\n", len); 
} 

所以,如果(srcbloc == NULL)(srcbloc == destbloc)程序會警告(退出)。如果其他測試中的任何一個匹配,將會打印警告,但該程序將繼續處理。