commit:     5afa37bd046ea35d9c68f43a1a28233bd0dbc7a7
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 27 20:36:39 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Mar 27 20:36:39 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5afa37bd

qgrep: squash truncation warning on Solaris

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 qgrep.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/qgrep.c b/qgrep.c
index fdabf9c..a2b6a98 100644
--- a/qgrep.c
+++ b/qgrep.c
@@ -449,6 +449,7 @@ int qgrep_main(int argc, char **argv)
                                if ((p = strchr(ebuild, '\n')) != NULL)
                                        *p = '\0';
                                if (show_name || (include_atoms != NULL)) {
+                                       size_t l;
                                        /* cut ".ebuild" */
                                        if (p == NULL)
                                                p = ebuild + strlen(ebuild);
@@ -460,8 +461,11 @@ int qgrep_main(int argc, char **argv)
                                        /* find head of the ebuild basename */
                                        if ((p = strchr(p, '/')) == NULL)
                                                continue;
-                                       /* find start of the pkg name */
-                                       snprintf(name, sizeof(name), "%s/%s", 
ebuild, (p+1));
+                                       /* find start of the pkg name, break up 
in two to
+                                        * avoid warning about possible 
truncation (very
+                                        * unlikely) */
+                                       l = snprintf(name, sizeof(name), "%s", 
ebuild);
+                                       snprintf(name + l, sizeof(name) - l, 
"%s", p);
                                        /* restore the filepath */
                                        *p = '/';
                                        *(p + strlen(p)) = '.';

Reply via email to