Parameter confusion #2a

by Michael S. Kaplan, published on 2005/10/22 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/10/22/483573.aspx


It was just ages ago that I talked about Parameter Confusion in regard to the LCMapString function when used for sort keys, and Parameter Confusion in regard to GetLocaleInfo when numbers were returned.

Perhaps it just seems that way.

Of course I forgot about a case in that second post -- LOCALE_FONTSIGNATURE. This particular LCType has the following in the documentation:

LOCALE_FONTSIGNATURE

Windows 95/98/Me, Windows NT 4.0 or later: A bit pattern used to determine the relationship between the character coverage needed to support the locale and the font contents. This information is returned in a LOCALESIGNATURE structure.

I am particularly proud of that bit in red, since it was added based on a bug I reported. :-)

Anyway, if you look at the structures you will see that a LOCALESIGNATURE sorta technically contains a FONTSIGNATURE:

typedef struct tagFONTSIGNATURE
{
    DWORD fsUsb[4];
    DWORD fsCsb[2];
} FONTSIGNATURE, *PFONTSIGNATURE,FAR *LPFONTSIGNATURE;

typedef struct tagLOCALESIGNATURE
{
    DWORD lsUsb[4];
    DWORD lsCsbDefault[2];
    DWORD lsCsbSupported[2];
} LOCALESIGNATURE, *PLOCALESIGNATURE,FAR *LPLOCALESIGNATURE;

Of course you see the problem in passing something the size of a FONTSIGNATURE and claiming it is the size of a LOCALESIGNATURE to make GetLocaleInfo happy, since it would inspire a small buffer overrun in the user code.

Which would kind of suck, obviously.

I personally reviewed one developer's work who had done just that in their code, which is one of the reasons I pushed for a doc change. :-)

Now, following the principles of that second Parameter Confusion post, cchDest is still expecting a count of characters, which means that the size of pass here is sizeof(LOCALESIGNATURE) / sizeof(TCHAR) and what to pass in the buffer is a LOCALESIGNATURE cast to a string so that the C compiler will not be unhappy with the parameter change.

Just a little more parameter confusion for an early Saturday morning....

 

This post brought to you by "ޟ" (U+079f, a.k.a. THAANA LETTER DAADHU)


# CornedBee on 22 Oct 2005 8:30 AM:

What I still don't understand is why it wouldn't have been easier to make multiple functions. Then each one could have exactly ONE return type (character buffer, dword or locale signature) and typesafe languages such as, uh, every single modern language that regularly accesses the API directly wouldn't have to make the programmer jump through hoops to make sure their code is correct.

# Michael S. Kaplan on 22 Oct 2005 1:30 PM:

Well, I don't entirely disagree with the sentiment (though I would not have added a whole new function for a LOCALESIGNATURE!).

But imagine if the Win32 API Headers were C++ style rather than requiring casts to change type. That would be a clearner way to handle these cases, if you ask me....

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2008/10/05 Can I get your [font]signature on this, please?

2006/02/08 They make 'em smarter than GetDateFormat

2006/01/12 The creation of sort keys does not always make sense

2005/12/19 It isn't a FONTSIGNATURE, darn it!

go to newer or older post, or back to index or month or day