帮忙看看是什么错误,谢谢

Taosim 2003-10-22 09:28:40
//db2abnd.c
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <locale.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <pwd.h>
#include "usersys.h"

void db2abnd(msg_dat)
struct msgdata *msg_dat;
{
int space;

memset((char *)&space,' ',sizeof(int));

if( msg_dat->d.errmno == space )
{
msg_dat->d.errmno = 0;
}

msg_dat->d.class1 = 9500;

memset(&msg_dat->d.command[7],NULL,1);

sprintf(msg_dat->d.msgdat, "%8s:ERR:DATABASE '%8s' ERROR",
msg_dat->d.pgname, msg_dat->d.command);

MSnd_Rcv(msg_dat, msg_dat);
}

//usersys.h
#define UMSGNOLEN 8 /* length of no */
#define UMSGIDLEN 16 /* length of id */
#define UMSGLEN 80 /* length of message */
#define UMSGDTLEN 500 /* length of data */

struct MSGDAT
{
int class1; /* message class1 */
int class2; /* message class2 */
int errmno; /* error message
int inpcnt; /* input count */
int outcnt; /* output count */
int inscnt; /* insert count */
int updcnt; /* update count */
int delcnt; /* delete count */
int fetcnt; /* fetch count */
int flsize; /* file size */
int sqlcod; /* sqlcode */
char command[UMSGNOLEN]; /* command name */
char msgno[UMSGNOLEN]; /* message number */
char pgname[UMSGIDLEN]; /* program name */
char htname[UMSGIDLEN]; /* host name */
char tablid[UMSGIDLEN]; /* table name */
char userid[UMSGIDLEN]; /* user id */
char dispid[UMSGIDLEN]; /* display id */
char msgdat[UMSGLEN]; /* message data */
char fldata[UMSGDTLEN]; /* data */
};

struct msgdata
{
long pid; /* process id */
struct MSGDAT d; /* message data */
};

程序编译执行时在if( msg_dat->d.errmno == space )处
发生错误,提示:Segmentation Fault - core dumped
谁能帮我解释一下是什么错误,谢谢。

...全文
53 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Taosim 2003-10-23
  • 打赏
  • 举报
回复
收到!谢谢。
snelgar 2003-10-22
  • 打赏
  • 举报
回复
struct msgdata *msg_dat;
只是定义了指针,并没有给它赋值,它指向的是一个不确定的地址,
对不应该访问的内存进行操作当然会core dump了
切记定义指针后要初始化,msg_dat=NULL;以防止类似的情况发生

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧