Merge pull request #15180 from gpanders/xcalloc

fix: fix incorrect call sites of xcalloc
This commit is contained in:
Thomas Vigouroux 2021-07-26 20:30:10 +02:00 committed by GitHub
commit ec7881bbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -315,7 +315,7 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id,
} }
rv.size = (size_t)(end - start); rv.size = (size_t)(end - start);
rv.items = xcalloc(sizeof(Object), rv.size); rv.items = xcalloc(rv.size, sizeof(Object));
if (!buf_collect_lines(buf, rv.size, start, if (!buf_collect_lines(buf, rv.size, start,
(channel_id != VIML_INTERNAL_CALL), &rv, err)) { (channel_id != VIML_INTERNAL_CALL), &rv, err)) {

View File

@ -1696,7 +1696,7 @@ void nvim_put(ArrayOf(String) lines, String type, Boolean after,
FUNC_API_SINCE(6) FUNC_API_SINCE(6)
FUNC_API_CHECK_TEXTLOCK FUNC_API_CHECK_TEXTLOCK
{ {
yankreg_T *reg = xcalloc(sizeof(yankreg_T), 1); yankreg_T *reg = xcalloc(1, sizeof(yankreg_T));
if (!prepare_yankreg_from_object(reg, type, lines.size)) { if (!prepare_yankreg_from_object(reg, type, lines.size)) {
api_set_error(err, kErrorTypeValidation, "Invalid type: '%s'", type.data); api_set_error(err, kErrorTypeValidation, "Invalid type: '%s'", type.data);
goto cleanup; goto cleanup;

View File

@ -50,7 +50,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id,
if (send_buffer) { if (send_buffer) {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 6; args.size = 6;
args.items = xcalloc(sizeof(Object), args.size); args.items = xcalloc(args.size, sizeof(Object));
// the first argument is always the buffer handle // the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);
@ -68,7 +68,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id,
if (line_count >= 1) { if (line_count >= 1) {
linedata.size = line_count; linedata.size = line_count;
linedata.items = xcalloc(sizeof(Object), line_count); linedata.items = xcalloc(line_count, sizeof(Object));
buf_collect_lines(buf, line_count, 1, true, &linedata, NULL); buf_collect_lines(buf, line_count, 1, true, &linedata, NULL);
} }
@ -93,7 +93,7 @@ void buf_updates_send_end(buf_T *buf, uint64_t channelid)
{ {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 1; args.size = 1;
args.items = xcalloc(sizeof(Object), args.size); args.items = xcalloc(args.size, sizeof(Object));
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);
rpc_send_event(channelid, "nvim_buf_detach_event", args); rpc_send_event(channelid, "nvim_buf_detach_event", args);
} }
@ -211,7 +211,7 @@ void buf_updates_send_changes(buf_T *buf,
// send through the changes now channel contents now // send through the changes now channel contents now
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 6; args.size = 6;
args.items = xcalloc(sizeof(Object), args.size); args.items = xcalloc(args.size, sizeof(Object));
// the first argument is always the buffer handle // the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);
@ -230,7 +230,7 @@ void buf_updates_send_changes(buf_T *buf,
if (num_added > 0) { if (num_added > 0) {
STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM"); STATIC_ASSERT(SIZE_MAX >= MAXLNUM, "size_t smaller than MAXLNUM");
linedata.size = (size_t)num_added; linedata.size = (size_t)num_added;
linedata.items = xcalloc(sizeof(Object), (size_t)num_added); linedata.items = xcalloc((size_t)num_added, sizeof(Object));
buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata, buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata,
NULL); NULL);
} }
@ -394,7 +394,7 @@ void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id)
{ {
Array args = ARRAY_DICT_INIT; Array args = ARRAY_DICT_INIT;
args.size = 2; args.size = 2;
args.items = xcalloc(sizeof(Object), args.size); args.items = xcalloc(args.size, sizeof(Object));
// the first argument is always the buffer handle // the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle); args.items[0] = BUFFER_OBJ(buf->handle);

View File

@ -1018,14 +1018,14 @@ static ExtmarkUndoObject *unserialize_extmark(bufinfo_T *bi, bool *error,
extup->type = type; extup->type = type;
if (type == kExtmarkSplice) { if (type == kExtmarkSplice) {
n_elems = (size_t)sizeof(ExtmarkSplice) / sizeof(uint8_t); n_elems = (size_t)sizeof(ExtmarkSplice) / sizeof(uint8_t);
buf = xcalloc(sizeof(uint8_t), n_elems); buf = xcalloc(n_elems, sizeof(uint8_t));
if (!undo_read(bi, buf, n_elems)) { if (!undo_read(bi, buf, n_elems)) {
goto error; goto error;
} }
extup->data.splice = *(ExtmarkSplice *)buf; extup->data.splice = *(ExtmarkSplice *)buf;
} else if (type == kExtmarkMove) { } else if (type == kExtmarkMove) {
n_elems = (size_t)sizeof(ExtmarkMove) / sizeof(uint8_t); n_elems = (size_t)sizeof(ExtmarkMove) / sizeof(uint8_t);
buf = xcalloc(sizeof(uint8_t), n_elems); buf = xcalloc(n_elems, sizeof(uint8_t));
if (!undo_read(bi, buf, n_elems)) { if (!undo_read(bi, buf, n_elems)) {
goto error; goto error;
} }