1
1

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
Этот коммит содержится в:
Benno Schulenberg 2014-06-04 16:30:11 +00:00
родитель 1de337de9c
Коммит 1eb23d4988
4 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -1,6 +1,14 @@
2014-06-04 David Lawrence Ramsey <pooka109@gmail.com>
* src/*.c: Adjustments of whitespace and comments.
* 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>
* doc/syntax/default.nanorc: Can't do trailing spaces in the

Просмотреть файл

@ -244,9 +244,9 @@ int do_lockfile(const char *filename)
{
char *lockdir = dirname((char *) mallocstrcpy(NULL, filename));
char *lockbase = basename((char *) mallocstrcpy(NULL, filename));
ssize_t lockfilesize = (sizeof (char *) * (strlen(filename)
+ strlen(locking_prefix) + strlen(locking_suffix) + 3));
char *lockfilename = (char *) nmalloc(lockfilesize);
size_t lockfilesize = strlen(filename) + strlen(locking_prefix)
+ strlen(locking_suffix) + 3;
char *lockfilename = charalloc(lockfilesize);
char lockprog[12], lockuser[16];
struct stat fileinfo;
int lockfd, lockpid;
@ -259,8 +259,8 @@ int do_lockfile(const char *filename)
if (stat(lockfilename, &fileinfo) != -1) {
ssize_t readtot = 0;
ssize_t readamt = 0;
char *lockbuf = (char *) nmalloc(8192);
char *promptstr = (char *) nmalloc(128);
char *lockbuf = charalloc(8192);
char *promptstr = charalloc(128);
int ans;
if ((lockfd = open(lockfilename, O_RDONLY)) < 0) {
statusbar(_("Error opening lock file %s: %s"),

Просмотреть файл

@ -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,
bool blank_after, bool viewok)
{
subnfunc *f = nmalloc(sizeof(subnfunc));
subnfunc *f = (subnfunc *)nmalloc(sizeof(subnfunc));
if (allfuncs == NULL)
allfuncs = f;

Просмотреть файл

@ -473,7 +473,7 @@ void do_undo(void)
#ifndef DISABLE_WRAPPING
case SPLIT:
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);
if (u->strdata2 != NULL)
f->next->data = mallocstrcpy(f->next->data, u->strdata2);
@ -510,7 +510,7 @@ void do_undo(void)
undidmsg = _("line break");
if (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]);
unlink_node(foo);
delete_node(foo);
@ -895,8 +895,8 @@ void add_undo(undo_type current_action)
if (u->begin != strlen(fs->current->data)) {
char *char_buf = charalloc(mb_cur_max() + 1);
int char_buf_len = parse_mbchar(&fs->current->data[u->begin], char_buf, NULL);
char_buf[char_buf_len] = '\0';
u->strdata = char_buf; /* Note: there is likely more memory allocated than necessary. */
null_at(&char_buf, char_buf_len);
u->strdata = char_buf;
u->mark_begin_x += char_buf_len;
break;
}