Add some NULL checks into recently modified output functions
After a merge with master where some strings we print (such as descriptions) could be NULL, a few segfaults popped up due to strlen() calls on null pointers. Fix this by doing some preemptive checks and returning from functions early if the string was null. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
105e01c8ef
commit
96f7613d15
2 changed files with 16 additions and 9 deletions
|
@ -592,7 +592,7 @@ void cb_dl_progress(const char *filename, int file_xfered, int file_total,
|
|||
/* Callback to handle notifications from the library */
|
||||
void cb_log(pmloglevel_t level, char *fmt, va_list args)
|
||||
{
|
||||
if(strlen(fmt) == 0) {
|
||||
if(!fmt || strlen(fmt) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -224,6 +224,10 @@ void indentprint(const char *str, int indent)
|
|||
const wchar_t *p;
|
||||
int len, cidx;
|
||||
|
||||
if(!str) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = strlen(str) + 1;
|
||||
wcstr = calloc(len, sizeof(wchar_t));
|
||||
len = mbstowcs(wcstr, str, len);
|
||||
|
@ -401,14 +405,17 @@ void list_display(const char *title, const alpm_list_t *list)
|
|||
int cols, len;
|
||||
wchar_t *wcstr;
|
||||
|
||||
if(title) {
|
||||
/* len goes from # bytes -> # chars -> # cols */
|
||||
len = strlen(title) + 1;
|
||||
wcstr = calloc(len, sizeof(wchar_t));
|
||||
len = mbstowcs(wcstr, title, len);
|
||||
len = wcswidth(wcstr, len);
|
||||
free(wcstr);
|
||||
|
||||
printf("%s ", title);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if(list) {
|
||||
for(i = list, cols = len; i; i = alpm_list_next(i)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue