[Rpm-maint] [rpm-software-management/rpm] Extend dbus-announce plugin (PR #3532)

Michal Domonkos notifications at github.com
Mon Feb 24 11:31:33 UTC 2025


@dmnks commented on this pull request.



> +        case TR_REMOVED:
+            op = "removed";
+            break;
+        case TR_RPMDB:
+            op = "rpmdb";
+            break;
+        case TR_RESTORED:
+            op = "restored";
+            break;
+        }
+        buffln = strlen(op) + 1 + strlen(nevra) + 1;
+        buff = (char *) malloc(sizeof(char) * buffln);
+        if (buff == NULL)
+            goto err;
+	/* encode as "operation SPACE nevra" */
+	snprintf(buff, buffln, "%s %s", op, nevra);

Oh, I should've mentioned `rasprintf()` here instead. It's a wrapper around the GNU extension `asprintf()` and allows you to get rid of the manual malloc and length calculation. Grep for it in rpm's source code to see some usage examples.

I just checked with @pmatilai and indeed, plugins should generally use rpm's helpers. So, if possible, please use those :)

Actually, same goes for the string array here. The rpm "canonical" way of handling string arrays is through the `argv*()` functions. There's also `argvFree()` which replaces the need to write the custom `free_array()` function here.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/pull/3532#discussion_r1967468642
You are receiving this because you are subscribed to this thread.

Message ID: <rpm-software-management/rpm/pull/3532/review/2636787045 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20250224/ddff22b3/attachment.htm>


More information about the Rpm-maint mailing list