libreadline7 segfault
Compiling a test program with libreadline7 and libhistory7 using bionic packages results in segfault.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <readline/
#include <readline/
/* A static variable for holding the line. */
static char *line_read = (char *)NULL;
/* Read a string, and return a pointer to it.
Returns NULL on EOF. */
char * rl_gets ()
{
/* If the buffer has already been allocated,
return the memory to the free pool. */
if (line_read)
{
free (line_read);
line_read = (char *)NULL;
}
/* Get a line from the user. */
line_read = readline ("");
/* If the line has any text in it,
save it on the history. */
if (line_read && *line_read)
add_history (line_read);
return (line_read);
}
int main(int argc, char **argv)
{
char *line = NULL;
printf(
using_history();
while (1)
{
line = rl_gets();
if (line) printf("You said: '%s'\n", line);
else printf("You said nothing..\n");
if (strncmp("q", line, 1) == 0) break;
}
printf("hej doo..\n");
return 0;
}
Compile:
hinxx@obzen ~/Projects/
Run:
hinxx@obzen ~/Projects/
hej..
test
You said: 'test'
Segmentation fault
The 'Segmentation fault' happens after pressing key UP on the keyboard.
gdb output:
hinxx@obzen ~/Projects/
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://
Find the GDB manual and other documentation resources online at:
<http://
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./readline...done.
(gdb) r ./readline
Starting program: /home/hinxx/
hej..
test
You said: 'test'
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff79b352b in previous_history () at ./history.c:196
warning: Source file is more recent than executable.
(gdb) bt
#0 0x00007ffff79b352b in previous_history () at ./history.c:196
#1 0x00007ffff79b30e5 in rl_get_
#2 0x00007ffff799625f in _rl_dispatch_subseq (key=65, map=<optimized out>, got_subseq=
#3 0x00007ffff79963c6 in _rl_dispatch_subseq (key=91, map=0x7ffff7bc7420 <emacs_
#4 0x00007ffff79963c6 in _rl_dispatch_subseq (key=27, map=0x7ffff7bc8440 <emacs_
#5 0x00007ffff79966a1 in _rl_dispatch (key=<optimized out>, map=<optimized out>) at ./readline.c:802
#6 0x00007ffff7996786 in readline_
#7 0x00007ffff7996f25 in readline_
#8 readline_internal () at ./readline.c:670
#9 readline (prompt=<optimized out>) at ./readline.c:376
#10 0x00005555555548d0 in rl_gets () at readline.c:24
#11 0x000055555555493b in main (argc=2, argv=0x7fffffff
This does not happen if '-lhistory' in not used at compile time.
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu readline Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Hinko Kocevar for more information if necessary.