aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-04-21 22:28:45 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-24 10:31:32 -0300
commitc68410de526eb39c1b9eb23b43603a61948ef42a (patch)
treed4023a6b56e5e2bd14ff03f5d625465e71358a90 /src
parent5421f8444387e810996ebde5af0bcb21fa484be2 (diff)
downloadrneovim-c68410de526eb39c1b9eb23b43603a61948ef42a.tar.gz
rneovim-c68410de526eb39c1b9eb23b43603a61948ef42a.tar.bz2
rneovim-c68410de526eb39c1b9eb23b43603a61948ef42a.zip
No OOM error condition in some ml_* functions
- ml_add_stack() - ml_encrypt_data() - ml_updatechunk()
Diffstat (limited to 'src')
-rw-r--r--src/memfile.c2
-rw-r--r--src/memline.c43
-rw-r--r--src/memline.h7
-rw-r--r--src/ops.c2
4 files changed, 17 insertions, 37 deletions
diff --git a/src/memfile.c b/src/memfile.c
index 4aad5470d2..497c9ddacd 100644
--- a/src/memfile.c
+++ b/src/memfile.c
@@ -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. */
if (*mfp->mf_buffer->b_p_key != NUL) {
data = ml_encrypt_data(mfp, data, offset, size);
- if (data == NULL)
- return FAIL;
}
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size)
diff --git a/src/memline.c b/src/memline.c
index dea6fceaf2..925ac3c7df 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -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
* stack */
- if ((top = ml_add_stack(buf)) < 0) {
- ++error;
- break; /* out of memory */
- }
+ top = ml_add_stack(buf);
ip = &(buf->b_ml.ml_stack[top]);
ip->ip_bnum = bnum;
ip->ip_index = idx;
@@ -1310,10 +1307,7 @@ void ml_recover(void)
/*
* going one block deeper in the tree
*/
- if ((top = ml_add_stack(buf)) < 0) { /* new entry in stack */
- ++error;
- break; /* out of memory */
- }
+ top = ml_add_stack(buf); // new entry in stack
ip = &(buf->b_ml.ml_stack[top]);
ip->ip_bnum = bnum;
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;
}
- if ((top = ml_add_stack(buf)) < 0) /* add new entry to stack */
- goto error_block;
+ top = ml_add_stack(buf); // add new entry to stack
ip = &(buf->b_ml.ml_stack[top]);
ip->ip_bnum = bnum;
ip->ip_low = low;
@@ -3262,25 +3255,19 @@ error_noblock:
/*
* 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)
{
- int top;
- infoptr_T *newstack;
-
- top = buf->b_ml.ml_stack_top;
+ int top = buf->b_ml.ml_stack_top;
/* may have to increase the stack size */
if (top == buf->b_ml.ml_stack_size) {
CHECK(top > 0, _("Stack size increases")); /* more than 5 levels??? */
- newstack = (infoptr_T *)alloc((unsigned)sizeof(infoptr_T) *
- (buf->b_ml.ml_stack_size + STACK_INCR));
- if (newstack == NULL)
- return -1;
- memmove(newstack, buf->b_ml.ml_stack,
- (size_t)top * sizeof(infoptr_T));
+ infoptr_T *newstack = xmalloc(sizeof(infoptr_T) *
+ (buf->b_ml.ml_stack_size + STACK_INCR));
+ memmove(newstack, buf->b_ml.ml_stack, (size_t)top * sizeof(infoptr_T));
vim_free(buf->b_ml.ml_stack);
buf->b_ml.ml_stack = newstack;
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
- * in allocated memory. Return NULL when out of memory.
- * Otherwise return "data".
+ * in allocated memory.
*/
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)
return data;
- new_data = (char_u *)alloc(size);
- if (new_data == NULL)
- return NULL;
+ new_data = xmalloc(size);
head_end = (char_u *)(&dp->db_index[dp->db_line_count]);
text_start = (char_u *)dp + 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)
return;
if (buf->b_ml.ml_chunksize == NULL) {
- buf->b_ml.ml_chunksize = (chunksize_T *)
- alloc((unsigned)sizeof(chunksize_T) * 100);
- if (buf->b_ml.ml_chunksize == NULL) {
- buf->b_ml.ml_usedchunks = -1;
- return;
- }
+ buf->b_ml.ml_chunksize = xmalloc(sizeof(chunksize_T) * 100);
buf->b_ml.ml_numchunks = 100;
buf->b_ml.ml_usedchunks = 1;
buf->b_ml.ml_chunksize[0].mlcs_numlines = 1;
diff --git a/src/memline.h b/src/memline.h
index c6aa757c8d..e7636fdc7d 100644
--- a/src/memline.h
+++ b/src/memline.h
@@ -1,6 +1,9 @@
#ifndef NEOVIM_MEMLINE_H
#define NEOVIM_MEMLINE_H
-/* memline.c */
+
+#include "types.h"
+#include "func_attr.h"
+
int ml_open(buf_T *buf);
void ml_set_crypt_key(buf_T *buf, char_u *old_key, int old_cm);
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);
void ml_setflags(buf_T *buf);
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,
unsigned size);
long ml_find_line_or_offset(buf_T *buf, linenr_T lnum, long *offp);
diff --git a/src/ops.c b/src/ops.c
index 97e629117e..2bb649a488 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -793,7 +793,7 @@ get_register (
if (copy) {
if (reg->y_size == 0) {
reg->y_array = NULL;
- } else
+ } else {
reg->y_array = xmalloc(reg->y_size * sizeof(char_u *));
for (linenr_T i = 0; i < reg->y_size; ++i) {
reg->y_array[i] = vim_strsave(y_current->y_array[i]);