splint ã¨ãã解æãã¼ã«ããã
MacOSX ã ã¨ããã©ã«ãã§ã¯å
¥ã£ã¦ããªãããã ãã©ãport install splint ã§ã¤ã³ã¹ãã¼ã«ã§ããã
ããã使ãäºã§ãã°ãæ··å¨ããããã³ã¼ãããæªä½¿ç¨ã®å¤æ°çã解æãã¦æãã¦ãããã
ãããã«ä½¿ã£ã¦ã¿ãã
以åæ¸ããæ£è¦è¡¨ç¾ã®ã½ã¼ã¹ããã§ãã¯ãã¦ã¿ãã
ã½ã¼ã¹ã¯ãããªå
容
1 /* $Id: regex.c 39 2008-05-19 16:25:42Z sugamasao $ */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <regex.h> 5 6 int main(void) { 7 char* str = "<p>hoge</p>"; 8 regex_t reg; 9 regmatch_t* pmatch; 10 size_t nmatch; 11 12 /* æ£è¦è¡¨ç¾ãªãã¸ã§ã¯ãã®çæ */ 13 if (regcomp(®, ">([[:alpha:]].+)<", REG_EXTENDED) != 0) { 14 puts("æ£è¦è¡¨ç¾ã§ãã¾ããï¼ï¼"); 15 return 1; 16 } 17 18 /* æ£è¦è¡¨ç¾æ ¼ç´ã¨ãªã¢ç¢ºä¿ */ 19 nmatch = reg.re_nsub+1; 20 pmatch = malloc(sizeof(regmatch_t) * nmatch); 21 22 /* æ£è¦è¡¨ç¾å®è¡ */ 23 if (regexec(®, str, nmatch, pmatch, 0) != 0) { 24 puts("è¦ã¤ãããªãã£ããï¼ï¼"); 25 return 1; 26 } 27 28 /* çµæåºå */ 29 { 30 int i = 0; 31 int j = 0; 32 for(i = 0; i < nmatch; i++) { 33 printf("match pattern[%d] = ", i); 34 for(j = pmatch[i].rm_so; j < pmatch[i].rm_eo; j++){ 35 printf("%c", str[j]); 36 } 37 puts(""); 38 } 39 } 40 41 free(pmatch); 42 return 0; 43 }
ãããã以ä¸ã®ãªãã·ã§ã³ãä»ãã¦è§£æãã¦ã¿ããã¡ãªã¿ã«ã解æã¬ãã«ã¯ããã©ã«ãã® standard ã使ç¨ãããæé«ã¬ãã«ã® strict ã使ãã¨æ°çãã®ãããªãã§ãã¯ãè¡ã£ã¦ãããã®ã§ãã¾ãå¬ãããªãã£ãã
ããããçµæï¼
Splint 3.1.1 --- 23 May 2008
regex.c: (in function main)
regex.c:14:3: Return value (type int) ignored: puts("æ£è¦è¡¨�...
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
regex.c:19:14: Access field of abstract type (regex_t): reg.re_nsub
An abstraction barrier is broken. If necessary, use /*@access@*/ to
allow access to an abstract type. (Use -abstract to inhibit warning)
regex.c:23:33: Possibly null storage pmatch passed as non-null param:
regexec (..., pmatch, ...)
A possibly null pointer is passed as a parameter corresponding to a formal
parameter with no /*@null@*/ annotation. If NULL may be used for this
parameter, add a /*@null@*/ annotation to the function parameter declaration.
(Use -nullpass to inhibit warning)
regex.c:20:11: Storage pmatch may become null
regex.c:24:3: Return value (type int) ignored: puts("è¦ã¤ã�...
regex.c:25:12: Fresh storage pmatch not released before return
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
regex.c:20:2: Fresh storage pmatch created
regex.c:32:14: Operands of < have incompatible types (int, size_t): i < nmatch
To allow arbitrary integral types to match any integral type, use
+matchanyintegral.
regex.c:34:8: Assignment of regoff_t to int: j = pmatch[i].rm_so
regex.c:34:29: Operands of < have incompatible types (int, regoff_t):
j < pmatch[i].rm_eo
regex.c:37:4: Return value (type int) ignored: puts("")Finished checking --- 9 code warnings
ãããªçãã½ã¼ã¹ãªã®ã«ãï¼åãææäºé
ãããããã ã
14è¡ç®ï¼puts ã®æ»ãå¤ã使ã£ã¦ãªãã¨ã©ã¼ï¼ãããã¯ç¡è¦ãã¦ãè¯ãé¡ãã ãã
19è¡ç®ï¼ãã¼ããæ¬å½ã¯ã¢ã¯ã»ã¹ãã¡ãã¾ãããã£ã¼ã«ã ã£ã¦ãã¨ï¼ããããããããããã¢ã¯ã»ã¹ããã®ããã¡ã ã£ãã¨ãã¦ãã©ããã¦æçµçãªæ£è¦è¡¨ç¾çµæãåãã°è¯ãã®ãã
23è¡ç®ï¼NULLãå
¥ãå¯è½æ§ãããã£ã¦ãã¨ãï¼ ãããã«ãmalloc å¾ã® NULL ãã§ãã¯ã¯ãã¦ããªãã
24è¡ç®ï¼ããã¯14è¡ç®ã¨ä¸ç·ã ãã
25è¡ç®ï¼ã©ãããã¡ã¢ãªãªã¼ã¯ãã¦ããããããï¼ï¼ï¼ãå¾ã§è¦æ¤è¨ãï¼
32è¡ç®ï¼intå㨠size_t åãæ¯è¼ãã¦ããããã
34è¡ç®ï¼åãéã代å
¥ãããã¦ãã & åãéãã®ã«æ¯è¼ãã¦ããï¼
37è¡ç®ï¼14è¡ç®ã¨åæ§
ã¨ããããã§ãããã«ç´ããã¨ããã¯ç´ãã¦ã¿ãã
ä¸é¨ãã£ã¤ãã ãã©
1 /* $Id: regex.c 39 2008-05-19 16:25:42Z sugamasao $ */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <regex.h> 5 6 int main(void) { 7 char* str = "<p>hoge</p>"; 8 regex_t reg; 9 regmatch_t* pmatch; 10 size_t nmatch; 11 12 /* æ£è¦è¡¨ç¾ãªãã¸ã§ã¯ãã®çæ */ 13 if (regcomp(®, ">([[:alpha:]].+)<", REG_EXTENDED) != 0) { 14 printf("æ£è¦è¡¨ç¾ã§ãã¾ããï¼ï¼\n"); 15 return 1; 16 } 17 18 /* æ£è¦è¡¨ç¾æ ¼ç´ã¨ãªã¢ç¢ºä¿ */ 19 nmatch = reg.re_nsub+1; 20 pmatch = malloc(sizeof(regmatch_t) * nmatch); 21 if (pmatch == NULL) { 22 printf("ã¡ã¢ãªç¢ºä¿å¤±æï¼ï¼"); 23 return 1; 24 } 25 26 /* æ£è¦è¡¨ç¾å®è¡ */ 27 if (regexec(®, str, nmatch, pmatch, 0) != 0) { 28 printf("è¦ã¤ãããªãã£ããï¼ï¼\n"); 29 return 1; 30 } 31 32 /* çµæåºå */ 33 { 34 size_t i = 0; 35 regoff_t j = 0; 36 for(i = 0; i < nmatch; i++) { 37 printf("match pattern[%d] = ", (int)i); 38 for(j = pmatch[i].rm_so; j < pmatch[i].rm_eo; j++){ 39 printf("%c", str[j]); 40 } 41 printf("\n"); 42 } 43 } 44 45 free(pmatch); 46 return 0; 47 }
ãã®ãã¨ãã¾ããã§ãã¯ãã¼ã«ãæãã¦ã¿ãã
A flag is not recognized or used in an incorrect way (Use -badflag to inhibit
warning)
regex.c: (in function main)
regex.c:19:14: Access field of abstract type (regex_t): reg.re_nsub
An abstraction barrier is broken. If necessary, use /*@access@*/ to
allow access to an abstract type. (Use -abstract to inhibit warning)
regex.c:29:12: Fresh storage pmatch not released before return
A memory leak has been detected. Storage allocated locally is not released
before the last reference to it is lost. (Use -mustfreefresh to inhibit
warning)
regex.c:20:2: Fresh storage pmatch createdFinished checking --- 2 code warnings
ã¾ã äºã¤æ®ã£ã¦ãããã¡ãã£ã¨ãã£ã¼ãªã³ã°ã§ããã«ã¯é£ããã®ã§æ¥æ¬èªã«ç¿»è¨³ããï¼¼(^o^)ï¼
æã¯èªèããããä¸æ£ç¢ºãªæ¹æ³ã§ä½¿ç¨ããã(è¦åãç¦æ¢ããã®ã«-badflagã使ç¨ãã)
regex.cã§ã¯ããã¾ãã: (æ©è½ã¡ã¤ã³ã®)
regex.c: 19:14: æ½è±¡å(regex_t)ã®åéã«ã¢ã¯ã»ã¹ãã¦ãã ãã: reg.re_nsub Anæ½è±¡
åããªã¢ã¯èµ·ä¼ãå¤ãã§ãã If necessary, use /*@access@*/ to
allow access to an abstract type. (è¦åãç¦æ¢ãã使ç¨è¦ç´)
regex.c: 29:12: ãªã¿ã¼ã³Aã¡ã¢ãªãªã¼ã¯ã®åã«ãªãªã¼ã¹ãããªãã£ãæ°é®®ãªã¹ãã¬ã¼ã¸
pmatchã¯æ¤åºããã¾ããã ããã®æå¾ã®åç §ãç¡ããªãåã«å±æçã«å²ãå½ã¦ãããã¹
ãã¬ã¼ã¸ã¯ãªãªã¼ã¹ããã¾ããã (è¦åãç¦æ¢ããã®ã«-mustfreefreshã使ç¨ãã¾ã)
regex.c: 20:2: pmatchãä½æããæ°é®®ãªã¹ãã¬ã¼ã¸ãã§ãã¯ãçµãã£ã¦ãã¾ãã--- 2 ã³ã¼ãè¦å
ãµããäºã¤ç®ã®æ¹ã¯ãã¤ã¾ãã20è¡ç®ã§ç¢ºä¿ããã¡ã¢ãªã解æ¾ããåã«ãã¸ãã¯ãæããç®æããããã£ã¦äºãã
確ãã«ãæ£è¦è¡¨ç¾å®è¡æã®ã¨ã©ã¼ãã§ãã¯ã§ã¡ã¢ãªã®è§£æ¾ãè¡ããã«æãã¦ããã試ãã«ãããã«ã free ãå
¥ãã¦ã¿ããã
26 /* æ£è¦è¡¨ç¾å®è¡ */ 27 if (regexec(®, str, nmatch, pmatch, 0) != 0) { 28 free(pmatch); // <---------ããã追å 29 printf("è¦ã¤ãããªãã£ããï¼ï¼\n"); 30 return 1; 31 }
ããã§å度å®è¡ããã
ãããæ¸ã£ããï¼
Splint 3.1.1 --- 23 May 2008
Command Line: Unrecognized option: -waek
A flag is not recognized or used in an incorrect way (Use -badflag to inhibit
warning)
regex.c: (in function main)
regex.c:19:14: Access field of abstract type (regex_t): reg.re_nsub
An abstraction barrier is broken. If necessary, use /*@access@*/ to
allow access to an abstract type. (Use -abstract to inhibit warning)Finished checking --- 1 code warning
ãã¼ã¼ã¼ã¼ã¼ã¼ã¼ã¼ãããã¯ããããããªããªããæ½è±¡åã§ã¢ã¯ã»ã¹ããã£ã¤ã£ã¦ããªãï¼ï¼
ããã人ãã¨ãã人ããããæãã¦ä¸ããï¼
ã¨ããããã§
ãã®ããã°ã©ã ã§ã¯ã»ã¨ãã©å®å®³ã¯ç¡ãããã©ãã¡ã¢ãªãªã¼ã¯ã®å¯è½æ§ãæ¤åºã§ãããããã¯ç®è¦ã§ãããããããªãè¯ãã®ã§ã¯ãªããã
ã¨ãããã standard ã§ããã§ãã¯ãå³ããããã®ããããªããªã
æ»ãå¤ã«å¯¾ãããã§ãã¯ãããªããã¨ãã®ãªãã·ã§ã³ã¯ãããã®ã®ããããããäºã«ãã£ã¦ä½ããã®ã¨ã©ã¼ãè¦éãå¯è½æ§ããããããã§ãã¯ãå¼±ãããã«ããæå¶ããã«ãããã¡ãã£ã¨æ©ã¾ããã¨ããã ã
èªåã¯ãã使ã£ã¦ãããï¼ãã¨ãã®ãã¦ãã¦ãããã°æãã¦ä¸ããï¼