newbie: memory fault(core dump)

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default newbie: memory fault(core dump)

    First I should admit that I am a real novice and the code I am
    submitting is directly out of UNIX System programming (1ed). It's a
    menu program (curses) that I want to alter but I can't get the example
    executable to run without getting a memory fault(core dump).

    The system is Tru64 UNIX, 5.1, Cc V6.3

    When it is compiled I get the following message:
    cc: Info: veg.c, line 58: In this statement, the return type for
    intrinsic "strlen" is being changed from "size_t" to "int".
    (intrinsicint)
    move(0, (COLS - strlen(m->m_title))/2);

    This is the only indication of an error I get. Can anyone spot a problem
    with the code?
    Much appreicated.
    Dp.




    /* Example use of domenu */

    #include <curses.h>
    #include "menu.h"


    /* This is the menu items. Change these to the values you
    want the user to choose from */

    char *mtab[8] = {
    "option 1",
    "option 2",
    "option 3",
    "",
    "option 4",
    "",
    "option 5",
    "option 6",
    };


    /* These are the definitions for the menu,
    the size, title and a pointer to the menu items */

    struct menu m1 = {
    8, 8,
    "Select an Option",
    &mtab[0]
    };


    /* The domenu routine -- handles a simple menu */

    domenu(m)
    struct menu *m;
    {

    int option, lastoption,j,c,y,x;
    char *p;

    /* Save current terminal state then set modes */
    savetty();

    cbreak(), nonl(); noecho(); standend();

    /* Empty screen */
    clear();

    /* initalise keypad, TRUE is defined in curses.h */
    keypad(stdscr, TRUE);

    /* print center title on line one */
    move(0, (COLS - strlen(m->m_title))/2);
    addstr(m->m_title);

    /* Work out position for top left corner of menu */
    y = (LINES - m->m_height)/2 + 1;
    x = (COLS - m->m_width)/2;

    /* display menu */
    for(j = 0;j < m->m_height; j++)
    mvaddstr(y+j, x, m->m_data[j]);

    /* Initial values for cursoe pos. and option setting */
    move( y, x);

    /* This assumes first line in menu isn't blank */
    lastoption = option = 0;

    for(;;) {

    /* remove hightlight bar from last option */
    if(lastoption != option)
    mvaddstr( lastoption+y, x,m->m_data[lastoption]);

    /* put hightlight bar on current option */
    standout();
    mvaddstr( option+y, x, m->m_data[option]);
    standend();
    move(option+y,x);

    /* Save current option */
    lastoption = option;

    refresh();

    /* process input */
    switch( (c = getch()) ) {

    case '\r': /* option selected */
    case '\n':
    if(option < 0) {
    beep();
    break;
    }

    /* restore initial state and return */
    resetty();
    return option;

    case KEY_DOWN: /* move current down */
    case KEY_RIGHT: /* move current right */

    do{
    option = (++option < m->m_height) ? option: 0;
    }while( isblank(m->m_data[option]) );
    break;

    case KEY_UP: /* move current line up or wrap */
    case KEY_LEFT: /* round */
    do{
    option = (--option >= 0) ? option : m->m_height -1;
    }while( isblank(m->m_data[option]));
    break;

    default: /* Try to match character */
    for(j = 0; j < m->m_height; j++){

    for(p = m->m_data[j]; *p == ' '; p++)
    ;



    if( *p == '\0') /* blank line */
    continue;

    if( *p == c){
    option = j;
    break;
    }
    if( j >= m->m_height) /* no match */
    beep();
    break;
    }
    }
    }

    }


    isblank(s) /* is string all spaces */
    char *s;
    {
    while( *s == ' ')
    s++;

    return *s == '\0' ? 1:0;
    }

    main()
    {

    /* initscr(); */
    domenu(&m1);
    endwin();
    }

    ======= menu.h file ========

    /* menu.h -- contains defintiions of menu struncture */

    struct menu {
    int m_height; /* menu height */
    int m_width; /* menu width */
    char *m_title; /* Menu title */
    char **m_data; /* pointer to data */
    };

    Dermot Paikkos Guest

  2. Similar Questions and Discussions

    1. ntpd core dump
      Hi all, I have 5.3-RELEASE installed. I'm trying to run ntpd but I get a message in /var/log/messages that it exited on signal 11 (core dumped)....
    2. Memory fault - core dumped on SCO OpenServer
      Everyone, I have a SCO OpenServer(TM) Release 3.2v5.0.5 machine that keeps giving me errors related to the printing process. I have included...
    3. ERROR: "memory fault - core dumped"
      Hello, I have an SCO Unix 5.0.5, Pentium II with 128MB of memory and a 20GB hard disk with enough room on it. There's a system developed in Basic...
    4. gcc program core dump
      There is a message of core dump may be related to the scope of variables , please any explainations . it's from a book of C .It is written as it is...
    5. How to dump core
      In article <B5cna.60949$jVh.46894@news01.bloor.is.net.cable.rogers.com>, "Samuel T" <none@none.com> writes: May be a bit late now, but try...
  3. #2

    Default Re: newbie: memory fault(core dump)

    >>> Dermot Paikkos wrote:

    DP> When it is compiled I get the following message:
    DP> cc: Info: veg.c, line 58: In this statement, the return type for
    DP> intrinsic "strlen" is being changed from "size_t" to "int".
    DP> (intrinsicint)
    DP> move(0, (COLS - strlen(m->m_title))/2);

    You forgot to #include <string.h>,
    and to #include <ctype.h>


    -netch-
    Valentin Nechayev Guest

  4. #3

    Default Re: newbie: memory fault(core dump)

    On Wed, 30 Jul 2003 12:17:42 +0000
    Dermot Paikkos <dermot22@sciencephoto.co.uk> wrote:
    > First I should admit that I am a real novice and the code I am
    > submitting is directly out of UNIX System programming (1ed). It's a
    > menu program (curses) that I want to alter but I can't get the example
    > executable to run without getting a memory fault(core dump).
    >
    > The system is Tru64 UNIX, 5.1, Cc V6.3
    >
    > When it is compiled I get the following message:
    > cc: Info: veg.c, line 58: In this statement, the return type for
    > intrinsic "strlen" is being changed from "size_t" to "int".
    > (intrinsicint)
    > move(0, (COLS - strlen(m->m_title))/2);
    That is just an info message from the compiler. DECC is generating
    functions, like strlen(3) as an instrinsic rather than executing
    strlen(3) from libc. It's just telling you that it is casting strlen to
    return a 32 bit int rather than a 64 bit long.

    --
    Jerry Feldman <gaf-nospam-at-blu.org>
    Boston Linux and Unix user group
    [url]http://www.blu.org[/url] PGP key id:C5061EA9
    PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
    Jerry Feldman Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139