Commit 1eb23d49 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Making use of the macros charalloc() and charealloc(), making use of

null_at(), adding a cast, and using an unsigned type for a length.
Patch by David Lawrence Ramsey.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4939 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 1de337de
Showing with 18 additions and 10 deletions
+18 -10
2014-06-04 David Lawrence Ramsey <pooka109@gmail.com> 2014-06-04 David Lawrence Ramsey <pooka109@gmail.com>
* src/*.c: Adjustments of whitespace and comments. * src/*.c: Adjustments of whitespace and comments.
* doc/nanorc.sample.in: Interpunction tweaks. * doc/nanorc.sample.in: Interpunction tweaks.
* src/global.c (add_to_funcs): Add cast to subnfunc* for nmalloc().
* src/files.c (do_lockfile): Properly make the variable 'lockfilesize'
a size_t instead of a ssize_t, since it holds the result of strlen().
And use charalloc() instead of (char *)nmalloc().
* src/text.c (do_undo): Use charealloc() and not (char *)nrealloc().
* src/text.c (add_undo): Make use of null_at() to both null-terminate
the multibyte character and align it to use only the amount of memory
necessary.
2014-06-02 Chris Allegretta <chrisa@asty.org> 2014-06-02 Chris Allegretta <chrisa@asty.org>
* doc/syntax/default.nanorc: Can't do trailing spaces in the * doc/syntax/default.nanorc: Can't do trailing spaces in the
......
...@@ -244,9 +244,9 @@ int do_lockfile(const char *filename) ...@@ -244,9 +244,9 @@ int do_lockfile(const char *filename)
{ {
char *lockdir = dirname((char *) mallocstrcpy(NULL, filename)); char *lockdir = dirname((char *) mallocstrcpy(NULL, filename));
char *lockbase = basename((char *) mallocstrcpy(NULL, filename)); char *lockbase = basename((char *) mallocstrcpy(NULL, filename));
ssize_t lockfilesize = (sizeof (char *) * (strlen(filename) size_t lockfilesize = strlen(filename) + strlen(locking_prefix)
+ strlen(locking_prefix) + strlen(locking_suffix) + 3)); + strlen(locking_suffix) + 3;
char *lockfilename = (char *) nmalloc(lockfilesize); char *lockfilename = charalloc(lockfilesize);
char lockprog[12], lockuser[16]; char lockprog[12], lockuser[16];
struct stat fileinfo; struct stat fileinfo;
int lockfd, lockpid; int lockfd, lockpid;
...@@ -259,8 +259,8 @@ int do_lockfile(const char *filename) ...@@ -259,8 +259,8 @@ int do_lockfile(const char *filename)
if (stat(lockfilename, &fileinfo) != -1) { if (stat(lockfilename, &fileinfo) != -1) {
ssize_t readtot = 0; ssize_t readtot = 0;
ssize_t readamt = 0; ssize_t readamt = 0;
char *lockbuf = (char *) nmalloc(8192); char *lockbuf = charalloc(8192);
char *promptstr = (char *) nmalloc(128); char *promptstr = charalloc(128);
int ans; int ans;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) { if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
statusbar(_("Error opening lock file %s: %s"), statusbar(_("Error opening lock file %s: %s"),
......
...@@ -296,7 +296,7 @@ function_type strtokeytype(const char *str) ...@@ -296,7 +296,7 @@ function_type strtokeytype(const char *str)
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help, void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
bool blank_after, bool viewok) bool blank_after, bool viewok)
{ {
subnfunc *f = nmalloc(sizeof(subnfunc)); subnfunc *f = (subnfunc *)nmalloc(sizeof(subnfunc));
if (allfuncs == NULL) if (allfuncs == NULL)
allfuncs = f; allfuncs = f;
......
...@@ -473,7 +473,7 @@ void do_undo(void) ...@@ -473,7 +473,7 @@ void do_undo(void)
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
case SPLIT: case SPLIT:
undidmsg = _("line wrap"); undidmsg = _("line wrap");
f->data = (char *) nrealloc(f->data, strlen(f->data) + strlen(u->strdata) + 1); f->data = charealloc(f->data, strlen(f->data) + strlen(u->strdata) + 1);
strcpy(&f->data[strlen(f->data) - 1], u->strdata); strcpy(&f->data[strlen(f->data) - 1], u->strdata);
if (u->strdata2 != NULL) if (u->strdata2 != NULL)
f->next->data = mallocstrcpy(f->next->data, u->strdata2); f->next->data = mallocstrcpy(f->next->data, u->strdata2);
...@@ -510,7 +510,7 @@ void do_undo(void) ...@@ -510,7 +510,7 @@ void do_undo(void)
undidmsg = _("line break"); undidmsg = _("line break");
if (f->next) { if (f->next) {
filestruct *foo = f->next; filestruct *foo = f->next;
f->data = (char *) nrealloc(f->data, strlen(f->data) + strlen(&f->next->data[u->mark_begin_x]) + 1); f->data = charealloc(f->data, strlen(f->data) + strlen(&f->next->data[u->mark_begin_x]) + 1);
strcat(f->data, &f->next->data[u->mark_begin_x]); strcat(f->data, &f->next->data[u->mark_begin_x]);
unlink_node(foo); unlink_node(foo);
delete_node(foo); delete_node(foo);
...@@ -895,8 +895,8 @@ void add_undo(undo_type current_action) ...@@ -895,8 +895,8 @@ void add_undo(undo_type current_action)
if (u->begin != strlen(fs->current->data)) { if (u->begin != strlen(fs->current->data)) {
char *char_buf = charalloc(mb_cur_max() + 1); char *char_buf = charalloc(mb_cur_max() + 1);
int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL); int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL);
char_buf[char_buf_len] = '\0'; null_at(&char_buf, char_buf_len);
u->strdata = char_buf; /* Note: there is likely more memory allocated than necessary. */ u->strdata = char_buf;
u->mark_begin_x += char_buf_len; u->mark_begin_x += char_buf_len;
break; break;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment