<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On 12 February 2013 00:14, Oleksii Shevchuk <span dir="ltr"><<a href="mailto:alxchk@gmail.com" target="_blank">alxchk@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Function that converts byte array to hex string<br>
---<br>
 src/shared/util.c | 23 +++++++++++++++++++++++<br>
 src/shared/util.h |  1 +<br>
 2 files changed, 24 insertions(+)<br>
<br>
diff --git a/src/shared/util.c b/src/shared/util.c<br>
index 24f9e7e..6dbfe29 100644<br>
--- a/src/shared/util.c<br>
+++ b/src/shared/util.c<br>
@@ -1368,6 +1368,29 @@ char hexchar(int x) {<br>
         return table[x & 15];<br>
 }<br>
<br>
+char * hexstr (const uint8_t *in, size_t count)<br>
+{<br>
+        char *r, *i = NULL;<br>
+<br>
+        if (!in || !count)<br>
+                goto finish;<br>
+<br>
+        r = i = new(char, count * 2 + 1);<br>
+        if (! r)<br>
+                goto finish;<br>
+<br>
+        while (count--) {<br>
+                *i++ = hexchar(*in >> 4);<br>
+                *i++ = hexchar(*in);<br>
+                ++in;<br>
+        }<br>
+<br>
+        *i = '\0';<br>
+<br>
+ finish:<br>
+        return r;<br>
+}<br>
+<br>
 int unhexchar(char c) {<br>
<br>
         if (c >= '0' && c <= '9')<br>
diff --git a/src/shared/util.h b/src/shared/util.h<br>
index cd13457..fe85fa8 100644<br>
--- a/src/shared/util.h<br>
+++ b/src/shared/util.h<br>
@@ -211,6 +211,7 @@ int get_process_uid(pid_t pid, uid_t *uid);<br>
 int get_process_gid(pid_t pid, gid_t *gid);<br>
<br>
 char hexchar(int x);<br>
+char * hexstr (const uint8_t *in, size_t count);<br>
 int unhexchar(char c);<br>
 char octchar(int x);<br>
 int unoctchar(char c);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.1.2<br>
<br>
_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
</font></span></blockquote></div><br></div><div class="gmail_extra">Hi,<br><br></div><div class="gmail_extra">I think you may be returning an unitialized "r" with your first "goto finish", you should set it to NULL like you do for i<br>

</div></div>