aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/buffer.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-05-09 00:39:17 +0200
committerGitHub <noreply@github.com>2017-05-09 00:39:17 +0200
commit0e873a30f3072dbacfb700f1e331a8c8396f2e1f (patch)
tree557792d454fef510a90975bed4e7d1650ee26c4f /src/nvim/api/buffer.c
parenta9981e0e7e9439340bb8c0162f860b78d8002559 (diff)
parent5b6d598ca8301682d931539ecd6da6a9fabae569 (diff)
downloadrneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.tar.gz
rneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.tar.bz2
rneovim-0e873a30f3072dbacfb700f1e331a8c8396f2e1f.zip
Merge #4411 from ZyX-I/luaviml'/lua
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r--src/nvim/api/buffer.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index 5de1535bce..0b8d39d0d2 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -195,7 +195,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
Object str = STRING_OBJ(cstr_to_string(bufstr));
// Vim represents NULs as NLs, but this may confuse clients.
- if (channel_id != INTERNAL_CALL) {
+ if (channel_id != VIML_INTERNAL_CALL) {
strchrsub(str.data.string.data, '\n', '\0');
}
@@ -295,6 +295,24 @@ void nvim_buf_set_lines(uint64_t channel_id,
return;
}
+ for (size_t i = 0; i < replacement.size; i++) {
+ if (replacement.items[i].type != kObjectTypeString) {
+ api_set_error(err,
+ kErrorTypeValidation,
+ "All items in the replacement array must be strings");
+ return;
+ }
+ // Disallow newlines in the middle of the line.
+ if (channel_id != VIML_INTERNAL_CALL) {
+ const String l = replacement.items[i].data.string;
+ if (memchr(l.data, NL, l.size)) {
+ api_set_error(err, kErrorTypeValidation,
+ "String cannot contain newlines");
+ return;
+ }
+ }
+ }
+
win_T *save_curwin = NULL;
tabpage_T *save_curtab = NULL;
size_t new_len = replacement.size;
@@ -303,27 +321,12 @@ void nvim_buf_set_lines(uint64_t channel_id,
char **lines = (new_len != 0) ? xcalloc(new_len, sizeof(char *)) : NULL;
for (size_t i = 0; i < new_len; i++) {
- if (replacement.items[i].type != kObjectTypeString) {
- api_set_error(err,
- kErrorTypeValidation,
- "All items in the replacement array must be strings");
- goto end;
- }
-
- String l = replacement.items[i].data.string;
+ const String l = replacement.items[i].data.string;
- // Fill lines[i] with l's contents. Disallow newlines in the middle of a
- // line and convert NULs to newlines to avoid truncation.
- lines[i] = xmallocz(l.size);
- for (size_t j = 0; j < l.size; j++) {
- if (l.data[j] == '\n' && channel_id != INTERNAL_CALL) {
- api_set_error(err, kErrorTypeException,
- "String cannot contain newlines");
- new_len = i + 1;
- goto end;
- }
- lines[i][j] = (char) (l.data[j] == '\0' ? '\n' : l.data[j]);
- }
+ // Fill lines[i] with l's contents. Convert NULs to newlines as required by
+ // NL-used-for-NUL.
+ lines[i] = xmemdupz(l.data, l.size);
+ memchrsub(lines[i], NUL, NL, l.size);
}
try_start();