免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2593 | 回复: 2
打印 上一主题 下一主题

setvbuf 导致core dump [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-07-20 20:05 |只看该作者 |倒序浏览
int OpenLogFile(char *FilName)
{   
    char    itasLogFile[256];
   
    memset(itasLogFile,0x00,sizeof(itasLogFile));

    if( NULL == getenv("ITASLOGDIR")){ /*获得环境变量中设置的程序的目录*/
        return FAILED;   
    }
    memcpy(itasLogFile,getenv("ITASLOGDIR"),strlen(getenv("ITASLOGDIR"))); /*保存环境变量*/
    strcat(itasLogFile,"/");
    strcat(itasLogFile,FilName);
    if((LogFile = fopen(itasLogFile,"a")) == NULL){

        return FAILED;
    }
    if(0!=(setvbuf(LogFile,NULL,_IONBF,0))){
        return FAILED;
    }
    return SUCCESS;
}



环境描述:AXI5.3
程序在执行到setvbuf一行时
直接coredump
用dbx查看core文件,信息如下:
(dbx) where
leftmost(??, ??) at 0xd03af44c
malloc_y(0x18, 0x0, 0x4, 0x0, 0x117b809f, 0x17b809f, 0x0, 0x0) at 0xd03b1204
malloc_common_80_63(??) at 0xd034260c
malloc(??) at 0xd0342460
setvbuf_unlocked(??, ??, ??, ??) at 0xd04a3d64
setvbuf(??, ??, ??, ??) at 0xd04a3ea8
OpenLogFile(FilName = "VTHDETOA20150708"), line 98 in "writelog.c"

还请各位大侠帮忙看下什么原因?

论坛徽章:
0
2 [报告]
发表于 2009-07-20 20:46 |只看该作者
所有的代码都贴出来

论坛徽章:
0
3 [报告]
发表于 2009-07-21 15:27 |只看该作者
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define FAILED -1
#define SUCCESS 10
FILE *LogFile;


int OpenLogFile( char *FilName )
{
&nbsp;&nbsp;&nbsp;&nbsp;char itasLogFile[256];

&nbsp;&nbsp;&nbsp;&nbsp;memset( itasLogFile, 0x00, sizeof( itasLogFile ) );

&nbsp;&nbsp;&nbsp;&nbsp;if( getenv( "ITASLOGDIR" ) == NULL )
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FAILED;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;memcpy( itasLogFile, getenv( "ITASLOGDIR" ), strlen( getenv( "ITASLOGDIR" ) ) );&nbsp;&nbsp;&nbsp;&nbsp;/*保存环境变量 */
&nbsp;&nbsp;&nbsp;&nbsp;strcat( itasLogFile, "/" );
&nbsp;&nbsp;&nbsp;&nbsp;strcat( itasLogFile, FilName );
&nbsp;&nbsp;&nbsp;&nbsp;if( ( LogFile = fopen( itasLogFile, "a" ) ) == NULL )
&nbsp;&nbsp;&nbsp;&nbsp;{

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FAILED;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;if( 0 != ( setvbuf( LogFile, NULL, _IONBF, 0 ) ) )
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FAILED;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;return SUCCESS;
}



int main( void )
{
&nbsp;&nbsp;&nbsp;&nbsp;putenv( "ITASLOGDIR=." );

&nbsp;&nbsp;&nbsp;&nbsp;OpenLogFile( "aa" );

&nbsp;&nbsp;&nbsp;&nbsp;fclose( LogFile );
&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}
简单测试之后 没有楼主所说问题呀
请检查你的程序
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP