summaryrefslogtreecommitdiff
path: root/third_party
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2011-04-12 12:25:55 -0400
committerMathias Stearn <mathias@10gen.com>2011-04-12 18:23:47 -0400
commitc68392bfe824cc4c8bae24fd9622d8872a05f98a (patch)
treee3a3fa815247334504eac14a354df68caa5a4b55 /third_party
parent9d8740619600d754389632a1e3fe8063bdea9784 (diff)
downloadmongo-c68392bfe824cc4c8bae24fd9622d8872a05f98a.tar.gz
don't SIGBUS when deleting at end of line
Diffstat (limited to 'third_party')
-rw-r--r--third_party/linenoise/linenoise.cpp10
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) {