On 12 February 2013 00:14, Oleksii Shevchuk <alx...@gmail.com> wrote:
> Function that converts byte array to hex string > --- > src/shared/util.c | 23 +++++++++++++++++++++++ > src/shared/util.h | 1 + > 2 files changed, 24 insertions(+) > > diff --git a/src/shared/util.c b/src/shared/util.c > index 24f9e7e..6dbfe29 100644 > --- a/src/shared/util.c > +++ b/src/shared/util.c > @@ -1368,6 +1368,29 @@ char hexchar(int x) { > return table[x & 15]; > } > > +char * hexstr (const uint8_t *in, size_t count) > +{ > + char *r, *i = NULL; > + > + if (!in || !count) > + goto finish; > + > + r = i = new(char, count * 2 + 1); > + if (! r) > + goto finish; > + > + while (count--) { > + *i++ = hexchar(*in >> 4); > + *i++ = hexchar(*in); > + ++in; > + } > + > + *i = '\0'; > + > + finish: > + return r; > +} > + > int unhexchar(char c) { > > if (c >= '0' && c <= '9') > diff --git a/src/shared/util.h b/src/shared/util.h > index cd13457..fe85fa8 100644 > --- a/src/shared/util.h > +++ b/src/shared/util.h > @@ -211,6 +211,7 @@ int get_process_uid(pid_t pid, uid_t *uid); > int get_process_gid(pid_t pid, gid_t *gid); > > char hexchar(int x); > +char * hexstr (const uint8_t *in, size_t count); > int unhexchar(char c); > char octchar(int x); > int unoctchar(char c); > -- > 1.8.1.2 > > _______________________________________________ > systemd-devel mailing list > systemd-devel@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/systemd-devel > Hi, 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
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel