{"id":1505,"date":"2015-01-06T14:18:34","date_gmt":"2015-01-06T06:18:34","guid":{"rendered":"http:\/\/www.51cos.com\/?p=1505"},"modified":"2015-03-17T21:29:59","modified_gmt":"2015-03-17T13:29:59","slug":"1505","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=1505","title":{"rendered":"C\u8bed\u8a00\uff1a\u5c0f\u5c0f\u6539\u8fdb\u63a5\u53e3\u51fd\u6570\uff0c\u65b9\u4fbf\u627e\u5230\u6b7b\u673a\u95ee\u9898\u7684\u7f6a\u9b41\u7978\u9996"},"content":{"rendered":"<p>\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6709\u7684\u51fd\u6570\u4f1a\u88ab\u5176\u4ed6\u4e0d\u540c\u7684\u51fd\u6570\u7ecf\u5e38\u8c03\u7528\uff0c<\/p>\n<p>\u7136\u540e\u53d1\u73b0\u6b7b\u673a\u95ee\u9898\uff0c\u4f46\u53c8\u4e0d\u6e05\u695a\u662f\u8c01\u8c03\u7528\u540e\u51fa\u73b0\u7684\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u65b9\u6cd5\uff0c\u7528\u6253\u5370\u6293\u4e00\u4e0b\u4fbf\u77e5\u3002<\/p>\n<p>20150317\u6539\u5584\u7248\uff0c\u5185\u5b58\u6cc4\u6f0f\u68c0\u67e5\u5de5\u5177\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"prettyprint linenums\" >\n<p>#include <stdio.h><br \/>\n#include <stdlib.h><\/p>\n<p>void *<br \/>\ndebug_malloc(size_t size, const char *file, int line, const char *func)<br \/>\n{<br \/>\n        void *p;<\/p>\n<p>        p = malloc(size);<br \/>\n        printf(\"%s:%d:%s:malloc(%ld): p=0x%lx\\n\",<br \/>\n            file, line, func, size, (unsigned long)p);<br \/>\n        return p;<br \/>\n}<\/p>\n<p>#define malloc(s) debug_malloc(s, __FILE__, __LINE__, __func__)<br \/>\n#define free(p)  do {                                                   \\<br \/>\n        printf(\"%s:%d:%s:free(0x%lx)\\n\", __FILE__, __LINE__,            \\<br \/>\n            __func__, (unsigned long)p);                                \\<br \/>\n        if(p){<br \/>\n            free(p);<br \/>\n        }<br \/>\n        p = NULL;<br \/>\n} while (0)<\/p>\n<p>int<br \/>\nmain(int argc, char *argv[])<br \/>\n{<br \/>\n        char *p;<br \/>\n        p = malloc(1024);<br \/>\n        free(p);<br \/>\n        return 0;<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>-----------------------------------------------------------------------------<\/p>\n<pre class=\"prettyprint linenums\">int check_mem_overflow(int maxlen,int curlen,char * func) {<\/p>\n<p>\t\t\tif(curlen &gt;= (maxlen - 1)){<br \/>\n\t\t\t\tprintf(\"FIXME:%s is out of memory!\\r\\n\",func);<br \/>\n\t\t\t\treturn 0;<br \/>\n\t\t\t}<br \/>\n\t\t\treturn 1;<\/p>\n<p>}<\/p>\n<p>\/\/\u4f7f\u7528\u4e3e\u4f8b<\/p>\n<p>void fuction()<br \/>\n{<\/p>\n<p>\t\u2026\u2026<\/p>\n<p>\tcheck_mem_overflow(MAXLEN,strlen(str),__func__);<\/p>\n<p>\t\u2026\u2026<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6709\u7684\u51fd\u6570\u4f1a\u88ab\u5176\u4ed6\u4e0d\u540c\u7684\u51fd\u6570\u7ecf\u5e38\u8c03\u7528\uff0c \u7136\u540e\u53d1\u73b0\u6b7b\u673a\u95ee\u9898\uff0c\u4f46\u53c8\u4e0d\u6e05\u695a\u662f\u8c01\u8c03\u7528\u540e\u51fa\u73b0\u7684\uff0c\u53ef\u4ee5\u7528\u4e0b\u9762\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1505","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/1505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1505"}],"version-history":[{"count":0,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/1505\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1505"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}