[PATCH] PR pch/39492 - MinGW memory mapping fix

Dave Korn dave.korn.cygwin@googlemail.com
Sun Mar 22 10:16:00 GMT 2009


Andrey Galkin wrote:

> One thing I don't like very much is "+ 10" in buffer size, but it's safe as
> the DWORD type is always a 32-bit unsigned int on MinGW. If there is a
> suitable constant/feature to use in GCC source it can be used there.

  It's not really the size of the DWORD type that defines how much buffer
space you need anyway; it's the size of the type denoted by the printf
conversion specifier.  Dunno if there's already such a constant, but how about

#define QUOTE(x) #x
#define ULONG_MAX_STRLEN   (strlen (QUOTE (ULONG_MAX))

  ... and then ...

  char object_name[sizeof (object_name_prefix) + ULONG_MAX_STRLEN];
  snprintf (object_name, sizeof(object_name), "%s%*.*lu", object_name_prefix,
            ULONG_MAX_STRLEN, ULONG_MAX_STRLEN,
            GetCurrentProcessId());

  The field size/precision specifiers don't do anything here since that's the
maximum size of the field anyway, but if anyone ever does change the format
specifier in the future (add another 'l' maybe) this will draw their attention
to the issue.

    cheers,
      DaveK



More information about the Gcc-patches mailing list