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
{
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;
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"),
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;
#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);
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);
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;
}