Skip to content

Commit

Permalink
GH-63 Fix occassional SIGSEGV when attempting to read the ANSI
Browse files Browse the repository at this point in the history
cursor position.  Do not think rlwrap supports ANSI report.
  • Loading branch information
SirWumpus committed Nov 8, 2024
1 parent 593797c commit d40f496
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/aline.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ alineInit(int hist_size)
static void
alineGetRowCol(int pos[2])
{
char report[12];
char *stop, report[12];
int n, fd = fileno(stdout);
(void) tcsetattr(fd, TCSANOW, &tty_modes[ALINE_RAW]);
(void) write(fd, ANSI_REPORT, sizeof (ANSI_REPORT)-1);
n = read(fd, report, sizeof (report));
report[n] = '\0';
pos[0] = (unsigned) strtoul(report+2, NULL, 10);
pos[1] = (unsigned) strtoul(strchr(report, ';')+1, NULL, 10);
pos[0] = (unsigned) strtoul(report+2, &stop, 10);
pos[1] = (unsigned) strtoul(stop+1, NULL, 10);
}
#endif

Expand Down Expand Up @@ -178,6 +178,7 @@ alineInput(FILE *fp, const char *prompt, char *buf, size_t size)
if (!isatty(fileno(fp))) {
*buf = '\0';
clearerr(fp); errno = 0;
(void) alineSetMode(ALINE_CANONICAL);
if (fgets(buf, size, fp) != NULL) {
return strlen(buf);
}
Expand Down

0 comments on commit d40f496

Please sign in to comment.