[pacman-dev] [PATCH 1/4] pm_asprintf logs 'failed to allocate' already
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 238e328..a1ec9c7 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -698,7 +698,6 @@ void signature_display(const char *title, alpm_siglist_t *siglist, for(i = 0; i < siglist->count; i++) { char *sigline; const char *status, *validity, *name; - int ret; alpm_sigresult_t *result = siglist->results + i; /* Don't re-indent the first result */ if(i != 0) { @@ -746,12 +745,8 @@ void signature_display(const char *title, alpm_siglist_t *siglist, break; } name = result->key.uid ? result->key.uid : result->key.fingerprint; - ret = pm_asprintf(&sigline, _("%s, %s from \"%s\""), + pm_asprintf(&sigline, _("%s, %s from \"%s\""), status, validity, name); - if(ret == -1) { - pm_printf(ALPM_LOG_ERROR, _("failed to allocate string\n")); - continue; - } indentprint(sigline, len, maxcols); printf("\n"); free(sigline); -- 1.8.2
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index a1ec9c7..994b79e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -689,7 +689,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist, if(title) { len = (unsigned short)string_length(title) + 1; - printf("%s ", title); + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(siglist->count == 0) { printf(_("None")); -- 1.8.2
On 26/03/13 04:43, Simon Gomizelj wrote:
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Ack - for pacman-4.1. Allan
diff --git a/src/pacman/util.c b/src/pacman/util.c index a1ec9c7..994b79e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -689,7 +689,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist,
if(title) { len = (unsigned short)string_length(title) + 1; - printf("%s ", title); + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(siglist->count == 0) { printf(_("None"));
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 8 ++++---- src/pacman/util.c | 34 ++++++++++++++++------------------ src/pacman/util.h | 3 ++- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 42a8635..3d1b108 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -40,21 +40,21 @@ * @param deps a list with items of type alpm_depend_t */ static void deplist_display(const char *title, - alpm_list_t *deps, unsigned short cols) + alpm_list_t *deps, unsigned short maxcols) { alpm_list_t *i, *text = NULL; for(i = deps; i; i = alpm_list_next(i)) { alpm_depend_t *dep = i->data; text = alpm_list_add(text, alpm_dep_compute_string(dep)); } - list_display(title, text, cols); + list_display(title, text, maxcols); FREELIST(text); } /** Turn a optdepends list into a text list. * @param optdeps a list with items of type alpm_depend_t */ -static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols) +static void optdeplist_display(alpm_pkg_t *pkg, unsigned short maxcols) { alpm_list_t *i, *text = NULL; for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) { @@ -69,7 +69,7 @@ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols) } text = alpm_list_add(text, depstring); } - list_display_linebreak(_("Optional Deps :"), text, cols); + list_display_linebreak(_("Optional Deps :"), text, maxcols); FREELIST(text); } diff --git a/src/pacman/util.c b/src/pacman/util.c index 994b79e..a5796bb 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -424,17 +424,20 @@ static size_t string_length(const char *s) return len; } -void string_display(const char *title, const char *string, unsigned short cols) +void string_display(const char *title, const char *string, + unsigned short maxcols) { + unsigned short len = 0; + if(title) { + len = (unsigned short)string_length(title) + 1; printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } + if(string == NULL || string[0] == '\0') { printf(_("None")); } else { - /* compute the length of title + a space */ - size_t len = string_length(title) + 1; - indentprint(string, (unsigned short)len, cols); + indentprint(string, (unsigned short)len, maxcols); } printf("\n"); } @@ -486,8 +489,6 @@ static void table_print_line(const alpm_list_t *line, short col_padding, printf("\n"); } - - /** * Find the max string width of each column. Also determines whether values * exist in the column and sets the value in has_data accordingly. @@ -615,19 +616,20 @@ static int table_display(const char *title, const alpm_list_t *header, void list_display(const char *title, const alpm_list_t *list, unsigned short maxcols) { - const alpm_list_t *i; - size_t len = 0; + unsigned short len = 0; if(title) { - len = string_length(title) + 1; + len = (unsigned short)string_length(title) + 1; printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } if(!list) { printf("%s\n", _("None")); } else { - size_t cols = len; + const alpm_list_t *i; const char *str = list->data; + size_t cols = len; + fputs(str, stdout); cols += string_length(str); for(i = alpm_list_next(list); i; i = alpm_list_next(i)) { @@ -667,15 +669,13 @@ void list_display_linebreak(const char *title, const alpm_list_t *list, printf("%s\n", _("None")); } else { const alpm_list_t *i; + /* Print the first element */ indentprint((const char *)list->data, len, maxcols); printf("\n"); /* Print the rest */ for(i = alpm_list_next(list); i; i = alpm_list_next(i)) { - size_t j; - for(j = 1; j <= len; j++) { - printf(" "); - } + printf("%-*s", (int)len, ""); indentprint((const char *)i->data, len, maxcols); printf("\n"); } @@ -691,6 +691,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist, len = (unsigned short)string_length(title) + 1; printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); } + if(siglist->count == 0) { printf(_("None")); } else { @@ -701,10 +702,7 @@ void signature_display(const char *title, alpm_siglist_t *siglist, alpm_sigresult_t *result = siglist->results + i; /* Don't re-indent the first result */ if(i != 0) { - size_t j; - for(j = 1; j <= len; j++) { - printf(" "); - } + printf("%-*s", (int)len, ""); } switch(result->status) { case ALPM_SIGSTATUS_VALID: diff --git a/src/pacman/util.h b/src/pacman/util.h index 0a2a6f7..690bc1d 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,7 +55,8 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols); size_t strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); -void string_display(const char *title, const char *string, unsigned short cols); +void string_display(const char *title, const char *string, + unsigned short maxcols); double humanize_size(off_t bytes, const char target_unit, int precision, const char **label); void list_display(const char *title, const alpm_list_t *list, -- 1.8.2
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 88 ---------------------------------------------------- src/pacman/util.h | 4 --- 3 files changed, 88 insertions(+), 92 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 3d1b108..ebbade1 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -36,6 +36,24 @@ #define CLBUF_SIZE 4096 +static void string_display(const char *title, const char *string, + unsigned short maxcols) +{ + unsigned short len = 0; + + if(title) { + len = (unsigned short)string_length(title) + 1; + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); + } + + if(string == NULL || string[0] == '\0') { + printf(_("None")); + } else { + indentprint(string, (unsigned short)len, maxcols); + } + printf("\n"); +} + /** Turn a depends list into a text list. * @param deps a list with items of type alpm_depend_t */ @@ -73,6 +91,76 @@ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short maxcols) FREELIST(text); } +static void signature_display(const char *title, alpm_siglist_t *siglist, + unsigned short maxcols) +{ + unsigned short len = 0; + + if(title) { + len = (unsigned short)string_length(title) + 1; + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); + } + + if(siglist->count == 0) { + printf(_("None")); + } else { + size_t i; + for(i = 0; i < siglist->count; i++) { + char *sigline; + const char *status, *validity, *name; + alpm_sigresult_t *result = siglist->results + i; + /* Don't re-indent the first result */ + if(i != 0) { + printf("%-*s", (int)len, ""); + } + switch(result->status) { + case ALPM_SIGSTATUS_VALID: + status = _("Valid"); + break; + case ALPM_SIGSTATUS_KEY_EXPIRED: + status = _("Key expired"); + break; + case ALPM_SIGSTATUS_SIG_EXPIRED: + status = _("Expired"); + break; + case ALPM_SIGSTATUS_INVALID: + status = _("Invalid"); + break; + case ALPM_SIGSTATUS_KEY_UNKNOWN: + status = _("Key unknown"); + break; + case ALPM_SIGSTATUS_KEY_DISABLED: + status = _("Key disabled"); + break; + default: + status = _("Signature error"); + break; + } + switch(result->validity) { + case ALPM_SIGVALIDITY_FULL: + validity = _("full trust"); + break; + case ALPM_SIGVALIDITY_MARGINAL: + validity = _("marginal trust"); + break; + case ALPM_SIGVALIDITY_NEVER: + validity = _("never trust"); + break; + case ALPM_SIGVALIDITY_UNKNOWN: + default: + validity = _("unknown trust"); + break; + } + name = result->key.uid ? result->key.uid : result->key.fingerprint; + pm_asprintf(&sigline, _("%s, %s from \"%s\""), + status, validity, name); + indentprint(sigline, len, maxcols); + printf("\n"); + free(sigline); + } + } +} + /** * Display the details of a package. * Extra information entails 'required by' info for sync packages and backup diff --git a/src/pacman/util.c b/src/pacman/util.c index a5796bb..14e5ae4 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -424,24 +424,6 @@ static size_t string_length(const char *s) return len; } -void string_display(const char *title, const char *string, - unsigned short maxcols) -{ - unsigned short len = 0; - - if(title) { - len = (unsigned short)string_length(title) + 1; - printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); - } - - if(string == NULL || string[0] == '\0') { - printf(_("None")); - } else { - indentprint(string, (unsigned short)len, maxcols); - } - printf("\n"); -} - static void table_print_line(const alpm_list_t *line, short col_padding, size_t colcount, size_t *widths, int *has_data) { @@ -682,76 +664,6 @@ void list_display_linebreak(const char *title, const alpm_list_t *list, } } -void signature_display(const char *title, alpm_siglist_t *siglist, - unsigned short maxcols) -{ - unsigned short len = 0; - - if(title) { - len = (unsigned short)string_length(title) + 1; - printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); - } - - if(siglist->count == 0) { - printf(_("None")); - } else { - size_t i; - for(i = 0; i < siglist->count; i++) { - char *sigline; - const char *status, *validity, *name; - alpm_sigresult_t *result = siglist->results + i; - /* Don't re-indent the first result */ - if(i != 0) { - printf("%-*s", (int)len, ""); - } - switch(result->status) { - case ALPM_SIGSTATUS_VALID: - status = _("Valid"); - break; - case ALPM_SIGSTATUS_KEY_EXPIRED: - status = _("Key expired"); - break; - case ALPM_SIGSTATUS_SIG_EXPIRED: - status = _("Expired"); - break; - case ALPM_SIGSTATUS_INVALID: - status = _("Invalid"); - break; - case ALPM_SIGSTATUS_KEY_UNKNOWN: - status = _("Key unknown"); - break; - case ALPM_SIGSTATUS_KEY_DISABLED: - status = _("Key disabled"); - break; - default: - status = _("Signature error"); - break; - } - switch(result->validity) { - case ALPM_SIGVALIDITY_FULL: - validity = _("full trust"); - break; - case ALPM_SIGVALIDITY_MARGINAL: - validity = _("marginal trust"); - break; - case ALPM_SIGVALIDITY_NEVER: - validity = _("never trust"); - break; - case ALPM_SIGVALIDITY_UNKNOWN: - default: - validity = _("unknown trust"); - break; - } - name = result->key.uid ? result->key.uid : result->key.fingerprint; - pm_asprintf(&sigline, _("%s, %s from \"%s\""), - status, validity, name); - indentprint(sigline, len, maxcols); - printf("\n"); - free(sigline); - } - } -} - /* creates a header row for use with table_display */ static alpm_list_t *create_verbose_header(void) { diff --git a/src/pacman/util.h b/src/pacman/util.h index 690bc1d..7200591 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,16 +55,12 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols); size_t strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); -void string_display(const char *title, const char *string, - unsigned short maxcols); double humanize_size(off_t bytes, const char target_unit, int precision, const char **label); void list_display(const char *title, const alpm_list_t *list, unsigned short maxcols); void list_display_linebreak(const char *title, const alpm_list_t *list, unsigned short maxcols); -void signature_display(const char *title, alpm_siglist_t *siglist, - unsigned short maxcols); void display_targets(void); int str_cmp(const void *s1, const void *s2); void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg); -- 1.8.2
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/package.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/pacman/util.c | 90 +--------------------------------------------------- src/pacman/util.h | 5 +-- 3 files changed, 90 insertions(+), 93 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 3d1b108..ebbade1 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -36,6 +36,24 @@ #define CLBUF_SIZE 4096 +static void string_display(const char *title, const char *string, + unsigned short maxcols) +{ + unsigned short len = 0; + + if(title) { + len = (unsigned short)string_length(title) + 1; + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); + } + + if(string == NULL || string[0] == '\0') { + printf(_("None")); + } else { + indentprint(string, (unsigned short)len, maxcols); + } + printf("\n"); +} + /** Turn a depends list into a text list. * @param deps a list with items of type alpm_depend_t */ @@ -73,6 +91,76 @@ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short maxcols) FREELIST(text); } +static void signature_display(const char *title, alpm_siglist_t *siglist, + unsigned short maxcols) +{ + unsigned short len = 0; + + if(title) { + len = (unsigned short)string_length(title) + 1; + printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); + } + + if(siglist->count == 0) { + printf(_("None")); + } else { + size_t i; + for(i = 0; i < siglist->count; i++) { + char *sigline; + const char *status, *validity, *name; + alpm_sigresult_t *result = siglist->results + i; + /* Don't re-indent the first result */ + if(i != 0) { + printf("%-*s", (int)len, ""); + } + switch(result->status) { + case ALPM_SIGSTATUS_VALID: + status = _("Valid"); + break; + case ALPM_SIGSTATUS_KEY_EXPIRED: + status = _("Key expired"); + break; + case ALPM_SIGSTATUS_SIG_EXPIRED: + status = _("Expired"); + break; + case ALPM_SIGSTATUS_INVALID: + status = _("Invalid"); + break; + case ALPM_SIGSTATUS_KEY_UNKNOWN: + status = _("Key unknown"); + break; + case ALPM_SIGSTATUS_KEY_DISABLED: + status = _("Key disabled"); + break; + default: + status = _("Signature error"); + break; + } + switch(result->validity) { + case ALPM_SIGVALIDITY_FULL: + validity = _("full trust"); + break; + case ALPM_SIGVALIDITY_MARGINAL: + validity = _("marginal trust"); + break; + case ALPM_SIGVALIDITY_NEVER: + validity = _("never trust"); + break; + case ALPM_SIGVALIDITY_UNKNOWN: + default: + validity = _("unknown trust"); + break; + } + name = result->key.uid ? result->key.uid : result->key.fingerprint; + pm_asprintf(&sigline, _("%s, %s from \"%s\""), + status, validity, name); + indentprint(sigline, len, maxcols); + printf("\n"); + free(sigline); + } + } +} + /** * Display the details of a package. * Extra information entails 'required by' info for sync packages and backup diff --git a/src/pacman/util.c b/src/pacman/util.c index a5796bb..3fe543e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -406,7 +406,7 @@ alpm_list_t *strsplit(const char *str, const char splitchar) return list; } -static size_t string_length(const char *s) +size_t string_length(const char *s) { int len; wchar_t *wcstr; @@ -424,24 +424,6 @@ static size_t string_length(const char *s) return len; } -void string_display(const char *title, const char *string, - unsigned short maxcols) -{ - unsigned short len = 0; - - if(title) { - len = (unsigned short)string_length(title) + 1; - printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); - } - - if(string == NULL || string[0] == '\0') { - printf(_("None")); - } else { - indentprint(string, (unsigned short)len, maxcols); - } - printf("\n"); -} - static void table_print_line(const alpm_list_t *line, short col_padding, size_t colcount, size_t *widths, int *has_data) { @@ -682,76 +664,6 @@ void list_display_linebreak(const char *title, const alpm_list_t *list, } } -void signature_display(const char *title, alpm_siglist_t *siglist, - unsigned short maxcols) -{ - unsigned short len = 0; - - if(title) { - len = (unsigned short)string_length(title) + 1; - printf("%s%s%s ", config->colstr.title, title, config->colstr.nocolor); - } - - if(siglist->count == 0) { - printf(_("None")); - } else { - size_t i; - for(i = 0; i < siglist->count; i++) { - char *sigline; - const char *status, *validity, *name; - alpm_sigresult_t *result = siglist->results + i; - /* Don't re-indent the first result */ - if(i != 0) { - printf("%-*s", (int)len, ""); - } - switch(result->status) { - case ALPM_SIGSTATUS_VALID: - status = _("Valid"); - break; - case ALPM_SIGSTATUS_KEY_EXPIRED: - status = _("Key expired"); - break; - case ALPM_SIGSTATUS_SIG_EXPIRED: - status = _("Expired"); - break; - case ALPM_SIGSTATUS_INVALID: - status = _("Invalid"); - break; - case ALPM_SIGSTATUS_KEY_UNKNOWN: - status = _("Key unknown"); - break; - case ALPM_SIGSTATUS_KEY_DISABLED: - status = _("Key disabled"); - break; - default: - status = _("Signature error"); - break; - } - switch(result->validity) { - case ALPM_SIGVALIDITY_FULL: - validity = _("full trust"); - break; - case ALPM_SIGVALIDITY_MARGINAL: - validity = _("marginal trust"); - break; - case ALPM_SIGVALIDITY_NEVER: - validity = _("never trust"); - break; - case ALPM_SIGVALIDITY_UNKNOWN: - default: - validity = _("unknown trust"); - break; - } - name = result->key.uid ? result->key.uid : result->key.fingerprint; - pm_asprintf(&sigline, _("%s, %s from \"%s\""), - status, validity, name); - indentprint(sigline, len, maxcols); - printf("\n"); - free(sigline); - } - } -} - /* creates a header row for use with table_display */ static alpm_list_t *create_verbose_header(void) { diff --git a/src/pacman/util.h b/src/pacman/util.h index 690bc1d..2566913 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,16 +55,13 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols); size_t strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); -void string_display(const char *title, const char *string, - unsigned short maxcols); +size_t string_length(const char *s); double humanize_size(off_t bytes, const char target_unit, int precision, const char **label); void list_display(const char *title, const alpm_list_t *list, unsigned short maxcols); void list_display_linebreak(const char *title, const alpm_list_t *list, unsigned short maxcols); -void signature_display(const char *title, alpm_siglist_t *siglist, - unsigned short maxcols); void display_targets(void); int str_cmp(const void *s1, const void *s2); void display_new_optdepends(alpm_pkg_t *oldpkg, alpm_pkg_t *newpkg); -- 1.8.2
On 03/25/13 at 02:43pm, Simon Gomizelj wrote:
Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> --- src/pacman/util.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/pacman/util.c b/src/pacman/util.c index 238e328..a1ec9c7 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -698,7 +698,6 @@ void signature_display(const char *title, alpm_siglist_t *siglist, for(i = 0; i < siglist->count; i++) { char *sigline; const char *status, *validity, *name; - int ret; alpm_sigresult_t *result = siglist->results + i; /* Don't re-indent the first result */ if(i != 0) { @@ -746,12 +745,8 @@ void signature_display(const char *title, alpm_siglist_t *siglist, break; } name = result->key.uid ? result->key.uid : result->key.fingerprint; - ret = pm_asprintf(&sigline, _("%s, %s from \"%s\""), + pm_asprintf(&sigline, _("%s, %s from \"%s\""), status, validity, name); - if(ret == -1) { - pm_printf(ALPM_LOG_ERROR, _("failed to allocate string\n")); - continue;
That continue shouldn't be removed so we don't try to print the invalid string.
- } indentprint(sigline, len, maxcols); printf("\n"); free(sigline); -- 1.8.2
apg
participants (3)
-
Allan McRae
-
Andrew Gregory
-
Simon Gomizelj