Re: memstat-0.9 hurd patch (PATH_MAX)
On Tue, Jan 24, 2012 at 09:46:16AM +0100, Tanguy LE CARROUR wrote:
> I hope I've fixed all the bugs in my patch, but I have one last small
> question: Do I really need to check if BUFSIZ is defined?
Yes, as it's a macro usually defined in libc headers.
As for this part :
+ buff_size = 11; /* size of the format string without "%x" expressions */
+ buff_size += sizeof(int) * 3 + 1;
+ buff_size += 1; // '\0'
+ buff = (char *)malloc((buff_size) * sizeof(char));
sprintf(buff, "/proc/%d/maps", pid);
You could do :
#define FORMAT "/proc/%d/maps"
#define BUFF_SIZE (sizeof(FORMAT) + (sizeof(int) * 3)) /* sizeof() already includes the terminating \0 */
buff = malloc(BUFF_SIZE);
if (buff == NULL)
handle_error();
sprintf(buff, FORMAT, pid);
#undef FORMAT
#undef BUFF_SIZE
--
Richard Braun
Reply to: