Commit 466fa780 by Peter Pentchev

Merge a prerelease of libdebug-0.5.1 into the Debian branch.

parents 030588b4 f7b9458f
Pipeline #1949932 skipped
Changelog for libdebug.
0.5.1 not yet ;)
- drop the sizeof(char) use in allocations; I don't think that
libdebug has ever been meant to be used on an architecture
where sizeof(char) != 1
Reported by: Jakub Wilk <jwilk@debian.org>
- fix the formatting of my copyright notices in the *.c files.
Reported by: Jakub Wilk <jwilk@debian.org>
- fix the hexdump buffer size on 64-bit architectures.
Reported by: Jakub Wilk <jwilk@debian.org>
- fix the bounded snprintf problems that I introduced in 0.5.0
Reported by: Jakub Wilk <jwilk@debian.org>
- let test_hex always output the last line of the test file,
even if the buffer is too short to store a newline
0.5.0 2016/03/20
- fix a compiler warning about a printf format string in hex.c
- set the version number explicitly in src/Makefile instead of
......
......@@ -35,7 +35,7 @@ TOPDIR = ..
# version
MAJOR = 0
MINOR = 5
PATCH = 0
PATCH = 1
# subdirectories (leave as is if there is no subdirectories)
DIR =
......
......@@ -29,6 +29,7 @@
*/
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
......@@ -41,29 +42,50 @@ static __inline__ int printable (int c)
return c >= 32 && c <= 126;
}
#define BUF_SIZE 81
#define BUF_SIZE 89
static size_t snprintf_bounded(char * const buf, const size_t len,
const char * const fmt, ...)
{
va_list v;
va_start(v, fmt);
const int res = vsnprintf(buf, len, fmt, v);
va_end(v);
if (res < 0)
{
if (len > 0)
buf[0] = '\0';
return 0;
}
else if ((size_t)res > len)
return len;
else
return res;
}
static void dump16 (char *buf,const uint8_t *s,uintptr_t offset,size_t len)
{
size_t i,n;
n = snprintf (buf, BUF_SIZE, "%08lx - ",(unsigned long)offset);
n = snprintf_bounded (buf, BUF_SIZE, "%08lx - ",(unsigned long)offset);
for (i = 0; i < len; i++)
n += snprintf(buf + n, BUF_SIZE - n, "%s%02x ",
n += snprintf_bounded(buf + n, BUF_SIZE - n, "%s%02x ",
i && !(i & 3)? " ": "", s[i]);
for ( ; i < 16; i++)
n += snprintf(buf + n, BUF_SIZE - n, "%s ",
n += snprintf_bounded(buf + n, BUF_SIZE - n, "%s ",
i && !(i & 3)? " ": "");
n += snprintf(buf + n, BUF_SIZE - n, " ");
n += snprintf_bounded(buf + n, BUF_SIZE - n, " ");
for (i = 0; i < len; i++)
n += snprintf(buf + n, BUF_SIZE - n, "%c",
n += snprintf_bounded(buf + n, BUF_SIZE - n, "%c",
printable (s[i]) ? s[i] : '.');
n += snprintf(buf + n, BUF_SIZE - n, "\n");
n += snprintf_bounded(buf + n, BUF_SIZE - n, "\n");
}
void hexdump_stub (const char *filename,int line,const char *function,int level,
......
/*
* Copyright (c) 2002-2004 Abraham vd Merwe <abz@blio.com>
# Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -116,13 +116,13 @@ static char *vbprintf (const char *fmt,va_list ap)
if (*fmt == '\0')
{
if ((buf = mem_alloc (sizeof (char))) == NULL)
if ((buf = mem_alloc (1)) == NULL)
return (NULL);
*buf = '\0';
return (buf);
}
if ((buf = mem_alloc (size * sizeof (char))) == NULL)
if ((buf = mem_alloc (size)) == NULL)
return (NULL);
for (;;)
......@@ -141,7 +141,7 @@ static char *vbprintf (const char *fmt,va_list ap)
else /* glibc 2.0 */
size *= 2; /* twice the old size */
if ((ptr = mem_realloc (buf,size * sizeof (char))) == NULL)
if ((ptr = mem_realloc (buf,size)) == NULL)
{
int saved = errno;
mem_free (buf);
......@@ -240,7 +240,7 @@ static char *prefix (struct log_private *priv,const char *filename,int line,cons
len += strlen (buf[i]);
}
if ((buf[4] = mem_alloc ((len + 1) * sizeof (char))) == NULL)
if ((buf[4] = mem_alloc (len + 1)) == NULL)
{
int saved = errno;
for (i = 0; i < n; i++)
......@@ -276,7 +276,7 @@ static int line_append (struct log_private *priv,const char *str)
if (priv->str != NULL)
{
size_t priv_len = strlen(priv->str);
if ((ptr = mem_realloc (priv->str,(len + priv_len) * sizeof (char))) == NULL)
if ((ptr = mem_realloc (priv->str,len + priv_len)) == NULL)
return (-1);
priv->str = ptr;
......@@ -284,7 +284,7 @@ static int line_append (struct log_private *priv,const char *str)
}
else
{
if ((priv->str = mem_alloc (len * sizeof (char))) == NULL)
if ((priv->str = mem_alloc (len)) == NULL)
return (-1);
snprintf(priv->str, len, "%s", str);
}
......@@ -589,7 +589,7 @@ int log_open (const char *logfile,int loglevel,int flags)
int saved;
size_t sz = strlen(logfile) + 1;
if ((log_private.filename = mem_alloc (sz * sizeof (char))) == NULL)
if ((log_private.filename = mem_alloc (sz)) == NULL)
return (-1);
if ((log_private.fd = open (logfile,O_CREAT | O_APPEND | O_WRONLY,S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0)
......@@ -736,7 +736,7 @@ int log_puts_stub (const char *filename,int line,const char *function,int level,
return (0);
size_t sz = strlen(str) + 1;
if ((s = mem_alloc (sizeof (char) * sz)) == NULL)
if ((s = mem_alloc (sz)) == NULL)
return (-1);
snprintf(s, sz, "%s", str);
......
/*
* Copyright (c) 2002-2004 Abraham vd Merwe <abz@blio.com>
# Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......
/*
* Copyright (c) 2002-2004 Abraham vd Merwe <abz@blio.com>
# Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* Copyright (c) 2016 Peter Pentchev <roam@ringlet.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
......@@ -120,6 +120,7 @@ int main (int argc,char *argv[])
}
hexdump (LOG_NORMAL,buf,length);
log_flush ();
mem_free (buf);
close (fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment