diff options
author | Mathias Stearn <mathias@10gen.com> | 2011-04-12 12:25:55 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2011-04-12 18:23:47 -0400 |
commit | c68392bfe824cc4c8bae24fd9622d8872a05f98a (patch) | |
tree | e3a3fa815247334504eac14a354df68caa5a4b55 /third_party | |
parent | 9d8740619600d754389632a1e3fe8063bdea9784 (diff) | |
download | mongo-c68392bfe824cc4c8bae24fd9622d8872a05f98a.tar.gz |
don't SIGBUS when deleting at end of line
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/linenoise/linenoise.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/third_party/linenoise/linenoise.cpp b/third_party/linenoise/linenoise.cpp index fc5757ca223..1154c6872ca 100644 --- a/third_party/linenoise/linenoise.cpp +++ b/third_party/linenoise/linenoise.cpp @@ -480,10 +480,12 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) errno = EAGAIN; return -1; case 127: /* delete */ - memmove(buf+pos,buf+pos+1,len-pos-1); - len--; - buf[len] = '\0'; - refreshLine(fd,prompt,buf,len,pos,cols); + if (len > 0 && pos < len) { + memmove(buf+pos,buf+pos+1,len-pos-1); + len--; + buf[len] = '\0'; + refreshLine(fd,prompt,buf,len,pos,cols); + } break; case 8: /* backspace or ctrl-h */ if (pos > 0 && len > 0) { |