首页 > 其他 > 详细

_tcsdup这个函数容易出现堆错误

时间:2015-04-09 19:11:48      阅读:208      评论:0      收藏:0      [点我收藏+]
#include <string.h>
#include <stdio.h>
#include <tchar>
int main( void )
{
   TCHAR buffer[] = _T("This is the buffer text");
   TCHAR *newstring;
   _tprintf( _T("Original: %s\n"), buffer );
   newstring = _tcsdup( buffer );
   _tprintf( _T("Copy:     %s\n"), newstring );
   free( newstring );
}

这是这个函数的标准调用demo,需要注意的是,即使buffer为空,返回的字符串也不是NULL,而是一个有地址的空字符串,这样直接判断地址是否为空,不为空再free会出错,这是改bug的体会

_tcsdup这个函数容易出现堆错误

原文:http://www.cnblogs.com/liaocheng/p/4410355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!