[질문] 에러가 왜 나는걸까여? 흐흐

익명 사용자의 이미지

질문이요..여기서..로그 메세지에 타입별로 생성하고자 하거든요.
Main함수에서 실제 값을 각각 넣어줘서, 필요한 시간값을 구하고,
그에 따른 로그 화일들을 생성하고자 하는 코드인데..
에러가 나요. 어데서 나는지 잘 몰르겠네요..ㅎㅎ
좀 살펴주심 고맙겠습니당. 별루 어려운거 아닌거 같은데...내가 몰라...서..T_T

#include
#include

/* Log type */
#define NETSTATE 1
#define THREADSTATE 2
#define ERRORLOG 3

struct logMsg {
char msg[256] ;
int type ;
char time_info[30] ;
};

char *getTime(time_t t) {
char time_Info[256] ;
time_t tt ;
tt = t ;
time(&tt) ;
memset(time_Info,0x00,sizeof(time_Info)) ;
strcpy(time_Info,ctime(&tt)) ;
return time_Info ;
}

FILE *fileOpen(char *name) {

FILE *file ;
file = fopen(name,"a") ;
return file ;

}

void log_msg(void *log) {
char msg[256] ;
size_t len ;
int log_type = 0 ;
struct logMsg *message = (struct logMsg *)log ;
char when[30] ;

memset(msg,0x00,sizeof(msg)) ;
memset(when,0x00,sizeof(when)) ;
// memset(recv_msg,0x00, sizeof(recv_msg)) ;
strcpy(when,message->time_info) ;
memset(msg, 0x00, sizeof(msg)) ;
strcpy(msg, message->msg) ;
log_type = message->type ;
switch(log_type) {

case 1 /* Network State Log */
fprintf(fileOpen("netState.log"),"%.24s",when) ;
fprintf(fileOpen("netState.log"), "/t %s\n", msg) ;

case 2 /* Thread Status Log*/
fprintf(fileOpen("thread.log"),"%.24s",when) ;
fprintf(fileOpen("thread.log"), "/t %s\n", msg) ;

case 3 /* Error Log message */
fprintf(fileOpen("error.log"),"%.24s",when) ;
fprintf(fileOpen("error.log"), "/t %s\n", msg) ;

default break;
}

}

int main(int argc, char** argv) {

time_t tt ;

struct logMsg *aa ;
aa->type = 1 ;
strcpy(aa->time_info,ctime(&tt)) ;
log_msg(&aa) ;
return 0 ;

}

익명 사용자의 이미지

struct logMsg *aa ;
aa->type = 1 ;
strcpy(aa->time_info,ctime(&tt)) ;

위를 보면 알겠지만 있지도 않은 "aa"의 메모리에 자료를
입력하고 있네요.

그리고 log_msg(&aa)여기에도 문제가 있네요.
원형은 log_msg(void *msg)인데 pointer를 "aa"또다시 번지연산자를
붇여 double point를 넘기는데, 받는쪽에서는 그냥 point로 쓰고
있네요. 또한 fileOpen을 사용하는것도 문제가 있네요.
여기에서 error가 발생하면 아마 이거 쓰는 프로그램들은 다 죽겠네요.

이런식의 프로그램은 쓰지 말기를 권장하는 대표적인 case가 되겠네요.
넘들이 좋은 참고할 거울이 되겠네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.