From c58e36c092ad5acc84d35e455ecc74096b25ae66 Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Sat, 28 Feb 2004 01:59:02 -0800 Subject: [PATCH] udev - safer sprintf() use Here is for now my last patch to the string handling for a rather theorethical case, where the node is very very very long. :) We have accordant to strfieldcat(to, from) now a strintcat(to, i) macro, which appends the ascii representation of a integer to a string in a safe way. --- udev.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'udev.h') diff --git a/udev.h b/udev.h index 3b676acf40..5737c84c9d 100644 --- a/udev.h +++ b/udev.h @@ -85,6 +85,18 @@ do { \ strncat(to, from, maxsize - strlen(to)-1); \ } while (0) +#define strintcat(to, i) \ +do { \ + to[sizeof(to)-1] = '\0'; \ + snprintf((to) + strlen(to), sizeof(to) - strlen(to)-1, "%u", i); \ +} while (0) + +#define strnintcat(to, i, maxsize) \ +do { \ + to[maxsize-1] = '\0'; \ + snprintf((to) + strlen(to), maxsize - strlen(to)-1, "%u", i); \ +} while (0) + static inline char *get_action(void) { char *action; -- cgit v1.2.3-54-g00ecf