Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Posts
    4

    Post Unanswered: please help quick

    hi there,
    it would be greatful if u help,i have been having this problem,i am making a program in c and connecting the to database mysql
    the program is like this

    #include<stdlib.h>
    #include<stdio.h>
    #include "include/mysql.h"
    #include<string.h>


    MYSQL mysql;
    MYSQL_RES *res;
    MYSQL_ROW row;


    int ipdel()
    {
    char sql[]="delete from IPMaster where IP_Address ='" ;
    char ip1[25];
    char *ip;

    int temp;

    mysql_init(&mysql);
    if(mysql_real_connect(&mysql,"localhost","project" ,"hi",NULL,0,NULL,0)==NULL)
    {
    printf("Can't connect to MySQL\n Reason :%s ",
    mysql_error(&mysql));
    }

    if(mysql_select_db(&mysql,"Status")!=0)
    {
    printf("Can't open the Database :%s",
    mysql_error(&mysql));
    }
    printf("Enter the IP Address to be Deleted :");
    scanf("%s",&ip1);
    ip=ip1;
    strcat(sql,ip);
    strcat(sql,"'");
    mysql_real_query(&mysql,sql,100);
    mysql_close(&mysql);

    return(0);
    }

    IP_Address is varchar(25) it is giving the segmentation fault after it deletes the entry from the table. and program terminates. it throws the SIGSEGV signal upon deletion could anybody help how to avoid this segmentation fault

    when i am running gdb it gives the output

    Program received signal SIGSEGV, Segmentation fault.
    0x804a507 in main ()
    (gdb) where
    #0 0x804a507 in main ()
    Cannot access memory at address 0x27312e31
    (gdb) list
    1 rtld.c: No such file or directory.
    (gdb) c
    Continuing.

    Program terminated with signal SIGSEGV, Segmentation fault.
    The program no longer exists.

  2. #2
    Join Date
    Apr 2003
    Location
    Rome, Italy
    Posts
    2

    Exclamation Change this!

    char sql[]="delete from IPMaster where IP_Address ='" ;

    to

    char sql[255]="delete from IPMaster where IP_Address ='" ;


    when you strcat sql you write bytes out of sql var space.

    Santino

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •