mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
No OOM error condition in some ml_* functions
- ml_add_stack() - ml_encrypt_data() - ml_updatechunk()
This commit is contained in:
parent
5421f84443
commit
c68410de52
@ -948,8 +948,6 @@ static int mf_write_block(memfile_T *mfp, bhdr_T *hp, off_t offset, unsigned siz
|
|||||||
/* Encrypt if 'key' is set and this is a data block. */
|
/* Encrypt if 'key' is set and this is a data block. */
|
||||||
if (*mfp->mf_buffer->b_p_key != NUL) {
|
if (*mfp->mf_buffer->b_p_key != NUL) {
|
||||||
data = ml_encrypt_data(mfp, data, offset, size);
|
data = ml_encrypt_data(mfp, data, offset, size);
|
||||||
if (data == NULL)
|
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size)
|
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size)
|
||||||
|
@ -508,10 +508,7 @@ void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm)
|
|||||||
|
|
||||||
/* going one block deeper in the tree, new entry in
|
/* going one block deeper in the tree, new entry in
|
||||||
* stack */
|
* stack */
|
||||||
if ((top = ml_add_stack(buf)) < 0) {
|
top = ml_add_stack(buf);
|
||||||
++error;
|
|
||||||
break; /* out of memory */
|
|
||||||
}
|
|
||||||
ip = &(buf->b_ml.ml_stack[top]);
|
ip = &(buf->b_ml.ml_stack[top]);
|
||||||
ip->ip_bnum = bnum;
|
ip->ip_bnum = bnum;
|
||||||
ip->ip_index = idx;
|
ip->ip_index = idx;
|
||||||
@ -1310,10 +1307,7 @@ void ml_recover(void)
|
|||||||
/*
|
/*
|
||||||
* going one block deeper in the tree
|
* going one block deeper in the tree
|
||||||
*/
|
*/
|
||||||
if ((top = ml_add_stack(buf)) < 0) { /* new entry in stack */
|
top = ml_add_stack(buf); // new entry in stack
|
||||||
++error;
|
|
||||||
break; /* out of memory */
|
|
||||||
}
|
|
||||||
ip = &(buf->b_ml.ml_stack[top]);
|
ip = &(buf->b_ml.ml_stack[top]);
|
||||||
ip->ip_bnum = bnum;
|
ip->ip_bnum = bnum;
|
||||||
ip->ip_index = idx;
|
ip->ip_index = idx;
|
||||||
@ -3190,8 +3184,7 @@ static bhdr_T *ml_find_line(buf_T *buf, linenr_T lnum, int action)
|
|||||||
goto error_block;
|
goto error_block;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((top = ml_add_stack(buf)) < 0) /* add new entry to stack */
|
top = ml_add_stack(buf); // add new entry to stack
|
||||||
goto error_block;
|
|
||||||
ip = &(buf->b_ml.ml_stack[top]);
|
ip = &(buf->b_ml.ml_stack[top]);
|
||||||
ip->ip_bnum = bnum;
|
ip->ip_bnum = bnum;
|
||||||
ip->ip_low = low;
|
ip->ip_low = low;
|
||||||
@ -3262,25 +3255,19 @@ error_noblock:
|
|||||||
/*
|
/*
|
||||||
* add an entry to the info pointer stack
|
* add an entry to the info pointer stack
|
||||||
*
|
*
|
||||||
* return -1 for failure, number of the new entry otherwise
|
* return number of the new entry
|
||||||
*/
|
*/
|
||||||
static int ml_add_stack(buf_T *buf)
|
static int ml_add_stack(buf_T *buf)
|
||||||
{
|
{
|
||||||
int top;
|
int top = buf->b_ml.ml_stack_top;
|
||||||
infoptr_T *newstack;
|
|
||||||
|
|
||||||
top = buf->b_ml.ml_stack_top;
|
|
||||||
|
|
||||||
/* may have to increase the stack size */
|
/* may have to increase the stack size */
|
||||||
if (top == buf->b_ml.ml_stack_size) {
|
if (top == buf->b_ml.ml_stack_size) {
|
||||||
CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */
|
CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */
|
||||||
|
|
||||||
newstack = (infoptr_T *)alloc((unsigned)sizeof(infoptr_T) *
|
infoptr_T *newstack = xmalloc(sizeof(infoptr_T) *
|
||||||
(buf->b_ml.ml_stack_size + STACK_INCR));
|
(buf->b_ml.ml_stack_size + STACK_INCR));
|
||||||
if (newstack == NULL)
|
memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T));
|
||||||
return -1;
|
|
||||||
memmove(newstack, buf->b_ml.ml_stack,
|
|
||||||
(size_t)top * sizeof(infoptr_T));
|
|
||||||
vim_free(buf->b_ml.ml_stack);
|
vim_free(buf->b_ml.ml_stack);
|
||||||
buf->b_ml.ml_stack = newstack;
|
buf->b_ml.ml_stack = newstack;
|
||||||
buf->b_ml.ml_stack_size += STACK_INCR;
|
buf->b_ml.ml_stack_size += STACK_INCR;
|
||||||
@ -4160,8 +4147,7 @@ void ml_setflags(buf_T *buf)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* If "data" points to a data block encrypt the text in it and return a copy
|
* If "data" points to a data block encrypt the text in it and return a copy
|
||||||
* in allocated memory. Return NULL when out of memory.
|
* in allocated memory.
|
||||||
* Otherwise return "data".
|
|
||||||
*/
|
*/
|
||||||
char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size)
|
char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned size)
|
||||||
{
|
{
|
||||||
@ -4174,9 +4160,7 @@ char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset, unsigned siz
|
|||||||
if (dp->db_id != DATA_ID)
|
if (dp->db_id != DATA_ID)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
new_data = (char_u *)alloc(size);
|
new_data = xmalloc(size);
|
||||||
if (new_data == NULL)
|
|
||||||
return NULL;
|
|
||||||
head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
|
head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
|
||||||
text_start = (char_u *)dp + dp->db_txt_start;
|
text_start = (char_u *)dp + dp->db_txt_start;
|
||||||
text_len = size - dp->db_txt_start;
|
text_len = size - dp->db_txt_start;
|
||||||
@ -4291,12 +4275,7 @@ static void ml_updatechunk(buf_T *buf, linenr_T line, long len, int updtype)
|
|||||||
if (buf->b_ml.ml_usedchunks == -1 || len == 0)
|
if (buf->b_ml.ml_usedchunks == -1 || len == 0)
|
||||||
return;
|
return;
|
||||||
if (buf->b_ml.ml_chunksize == NULL) {
|
if (buf->b_ml.ml_chunksize == NULL) {
|
||||||
buf->b_ml.ml_chunksize = (chunksize_T *)
|
buf->b_ml.ml_chunksize = xmalloc(sizeof(chunksize_T) * 100);
|
||||||
alloc((unsigned)sizeof(chunksize_T) * 100);
|
|
||||||
if (buf->b_ml.ml_chunksize == NULL) {
|
|
||||||
buf->b_ml.ml_usedchunks = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
buf->b_ml.ml_numchunks = 100;
|
buf->b_ml.ml_numchunks = 100;
|
||||||
buf->b_ml.ml_usedchunks = 1;
|
buf->b_ml.ml_usedchunks = 1;
|
||||||
buf->b_ml.ml_chunksize[0].mlcs_numlines = 1;
|
buf->b_ml.ml_chunksize[0].mlcs_numlines = 1;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#ifndef NEOVIM_MEMLINE_H
|
#ifndef NEOVIM_MEMLINE_H
|
||||||
#define NEOVIM_MEMLINE_H
|
#define NEOVIM_MEMLINE_H
|
||||||
/* memline.c */
|
|
||||||
|
#include "types.h"
|
||||||
|
#include "func_attr.h"
|
||||||
|
|
||||||
int ml_open(buf_T *buf);
|
int ml_open(buf_T *buf);
|
||||||
void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm);
|
void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm);
|
||||||
void ml_setname(buf_T *buf);
|
void ml_setname(buf_T *buf);
|
||||||
@ -35,7 +38,7 @@ char_u *makeswapname(char_u *fname, char_u *ffname, buf_T *buf,
|
|||||||
char_u *get_file_in_dir(char_u *fname, char_u *dname);
|
char_u *get_file_in_dir(char_u *fname, char_u *dname);
|
||||||
void ml_setflags(buf_T *buf);
|
void ml_setflags(buf_T *buf);
|
||||||
char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset,
|
char_u *ml_encrypt_data(memfile_T *mfp, char_u *data, off_t offset,
|
||||||
unsigned size);
|
unsigned size) FUNC_ATTR_NONNULL_RET;
|
||||||
void ml_decrypt_data(memfile_T *mfp, char_u *data, off_t offset,
|
void ml_decrypt_data(memfile_T *mfp, char_u *data, off_t offset,
|
||||||
unsigned size);
|
unsigned size);
|
||||||
long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp);
|
long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp);
|
||||||
|
@ -793,7 +793,7 @@ get_register (
|
|||||||
if (copy) {
|
if (copy) {
|
||||||
if (reg->y_size == 0) {
|
if (reg->y_size == 0) {
|
||||||
reg->y_array = NULL;
|
reg->y_array = NULL;
|
||||||
} else
|
} else {
|
||||||
reg->y_array = xmalloc(reg->y_size * sizeof(char_u *));
|
reg->y_array = xmalloc(reg->y_size * sizeof(char_u *));
|
||||||
for (linenr_T i = 0; i < reg->y_size; ++i) {
|
for (linenr_T i = 0; i < reg->y_size; ++i) {
|
||||||
reg->y_array[i] = vim_strsave(y_current->y_array[i]);
|
reg->y_array[i] = vim_strsave(y_current->y_array[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user