assert(path != NULL);
if(*path == '/') {
- *var = strdup(path);
+ *var = xstrdup(path);
return;
}
ret = *database[item][EMAIL] ?
mkstr("%s <%s>", name, email) :
- strdup(name);
+ xstrdup(name);
free(name);
}
memset(item, 0, sizeof(item));
- item[NAME] = strdup(name);
- item[EMAIL] = strdup(email);
+ item[NAME] = xstrdup(name);
+ item[EMAIL] = xstrdup(email);
add_item2database(item);
return 1;
#define safe_atoi(X) ((X == NULL) ? 0 : atoi(X))
#define safe_str(X) ((X == NULL) ? "" : X)
-#define safe_strdup(X) ((X == NULL) ? NULL : strdup(X))
#ifndef min
# define min(x,y) (((x)<(y)) ? (x):(y))
*tmp++ = '\0';
for(i = 0; i < ITEM_FIELDS; i++)
if(!strcmp(abook_fields[i].key, line)) {
- item[i] = strdup(tmp);
+ item[i] = xstrdup(tmp);
goto next;
}
}
char *tmp;
if(item[EMAIL] == NULL)
- item[EMAIL] = strdup("");
+ item[EMAIL] = xstrdup("");
for(i=0; i<ITEM_FIELDS; i++)
if( item[i] && ((int)strlen(item[i]) > _MAX_FIELD_LEN(i) ) ) {
tmp = item[i];
item[i][_MAX_FIELD_LEN(i)-1] = 0;
- item[i] = strdup(item[i]);
+ item[i] = xstrdup(item[i]);
free(tmp);
}
}
while(p > s && *(p - 1) != ' ')
p--;
- return strdup(p);
+ return xstrdup(p);
}
static int
if(list_is_empty() || !is_valid_item(start))
return -2; /* error */
- findstr = strdup(str);
+ findstr = xstrdup(str);
findstr = strlower(findstr);
e.item = start - 1; /* must be "real start" - 1 */
db_enumerate_items(e) {
- for( i = 0; search_fields[i] >= 0; i++ ) {
- tmp = safe_strdup(database[e.item][search_fields[i]]);
+ for(i = 0; search_fields[i] >= 0; i++) {
+ if(database[e.item][search_fields[i]] == NULL)
+ continue;
+ tmp = xstrdup(database[e.item][search_fields[i]]);
if( tmp && strstr(strlower(tmp), findstr) ) {
ret = e.item;
goto out;
}
backup = xmalloc(sizeof(list_item));
for(i = 0; i < ITEM_FIELDS; i++)
- backup[0][i] = safe_strdup(database[item][i]);
+ if(database[item][i] == NULL)
+ backup[0][i] = NULL;
+ else
+ backup[0][i] =
+ xstrdup(database[item][i]);
break;
case RESTORE_ITEM:
if(backup) {
{
char *tmp;
- tmp = strdup(*field);
+ tmp = xstrdup(*field);
change_field("Name: ", field);
if(*field == NULL || ! **field) {
xfree(*field);
- *field = strdup(tmp);
+ *field = xstrdup(tmp);
}
xfree(tmp);
int email_num = c - '2';
split_emailstr(item, emails);
- field = strdup(emails[email_num]);
+ field = xstrdup(emails[email_num]);
if(change_field("E-mail: ", &field))
return; /* user cancelled ( C-g ) */
if(tmp[len -1] == ',')
tmp[len-1] =0;
- database[item][EMAIL] = strdup(tmp);
+ database[item][EMAIL] = xstrdup(tmp);
}
static int
pwent = getpwnam(username);
- if((tmp = strdup(pwent->pw_gecos)) == NULL)
- return strdup(username);
+ if((tmp = xstrdup(pwent->pw_gecos)) == NULL)
+ return xstrdup(username);
rtn = sscanf(pwent->pw_gecos, "%[^,]", tmp);
if (rtn == EOF || rtn == 0) {
free(tmp);
- return strdup(username);
+ return xstrdup(username);
} else
return tmp;
}
for(i=0; i < LDIF_ITEM_FIELDS; i++) {
if(ldif_conv_table[i] >= 0 && li[i] && *li[i] )
- abook_item[ldif_conv_table[i]] = strdup(li[i]);
+ abook_item[ldif_conv_table[i]] = xstrdup(li[i]);
}
add_item2database(abook_item);
break;
if(item[i])
xfree(item[i]);
- item[i] = strdup(value);
+ item[i] = xstrdup(value);
}
}
}
while(ISSPACE(*ptr))
ptr++;
- *rest = strdup(ptr);
+ *rest = xstrdup(ptr);
free(line);
return 0;
strncpy(tmp, start, len);
tmp[len] = 0;
if(*tmp)
- item[pine_conv_table[i]] = strdup(tmp);
+ item[pine_conv_table[i]] = xstrdup(tmp);
}
start = end + 1;
}
char *copy, *trimmed;
int len;
- copy = trimmed = strdup(s);
+ copy = trimmed = xstrdup(s);
strtrim(trimmed);
len = strlen(trimmed);
}
trimmed[len - 1] = 0;
trimmed++;
- trimmed = strdup(trimmed);
+ trimmed = xstrdup(trimmed);
free(copy);
return trimmed;
}
xfree(copy);
- return strdup(s);
+ return xstrdup(s);
}
static void
char *tmp, *pos;
if(database[i][NICK])
- return strdup(database[i][NICK]);
+ return xstrdup(database[i][NICK]);
- tmp = strdup(database[i][NAME]);
+ tmp = xstrdup(database[i][NAME]);
if( ( pos = strchr(tmp, ' ') ) )
*pos = 0;
#include "list.h"
#include "misc.h"
#include "options.h"
+#include "xmalloc.h"
#define MIN_EXTRA_COLUMN ADDRESS /* 2 */
#define MAX_EXTRA_COLUMN LAST_FIELD
return 1;
for(i = 0; i < ITEM_FIELDS; i++)
- item[i] = database[curitem][i] ? strdup(database[curitem][i]) :
+ item[i] = database[curitem][i] ? xstrdup(database[curitem][i]) :
NULL;
if(add_item2database(item))
#include "options.h"
#include "abook.h"
#include "misc.h"
+#include "xmalloc.h"
#ifndef FALSE
# define FALSE 0
if(str_opts[opt])
free(str_opts[opt]);
- str_opts[opt] = strdup(value);
+ str_opts[opt] = xstrdup(value);
}
int
#include "misc.h"
#include "options.h"
#include "filter.h"
+#include "xmalloc.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
load_database(datafile);
} else {
free(datafile);
- datafile = strdup(filename);
+ datafile = xstrdup(filename);
}
refresh_screen();
return ptr;
}
+char *
+xstrdup(const char *s)
+{
+ size_t len = strlen(s);
+ void *new;
+
+ new = xmalloc_inc(len, 1);
+ if(new == NULL)
+ return NULL;
+
+ return (char *)memcpy(new, s, len + 1);
+}
+
void * xmalloc_inc(size_t, size_t);
void * xrealloc(void *, size_t);
void * xrealloc_inc(void *, size_t, size_t);
+char * xstrdup(const char *s);
#define xfree(ptr) do { free(ptr); ptr = NULL; } while(0)