Re: TCHAR and buffer overflows
From: Alun Jones (alun@texis.com)Date: 08/26/02
- Next message: Alun Jones: "Re: Privilege-escalation attacks on NT-based Windows are unfixable"
- Previous message: Alun Jones: "Re: TCHAR and buffer overflows"
- In reply to: Edward Elliott: "Re: TCHAR and buffer overflows"
- Next in thread: those who know me have no need of my name: "Re: TCHAR and buffer overflows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: alun@texis.com (Alun Jones) Date: Mon, 26 Aug 2002 21:23:32 GMT
In article <3D6A8140.2090405@127.0.0.1>, Edward Elliott <nobody@127.0.0.1>
wrote:
>Alun Jones wrote:
>> One of my standard #defines is "#define countof(x) (sizeof(x)/sizeof(*x))"
>>
>> I never use sizeof when I mean countof!
>
>Just an aside, I wonder what happens to your macro when fed a C99
>variable length array:
>
>void foo(size_t x)
>{
> int bar[x];
> countof(bar);
>}
To be honest, I don't know. I don't believe my current compiler supports that
- it says "expected constant expression" on the line "int bar[x]".
>Which is to really ask, what happens to sizeof when used on such
>constructs? sizeof is evaluated at compile-time, not run-time. Would
>"sizeof bar" just return the base size of the data type, i.e. "sizeof
>int"? It can't possibly return the size of the array at compile time
>since it isn't known. It appears C99 breaks sizeof constructs for VLAs.
Maybe sizeof(bar) would be a compiler error, since, as you say, the size can
not be determined at run-time, and yet the array definitely has a size, rather
than being an unsized array (where countof always returns 1).
Alun.
~~~~
[Please don't email posters, if a Usenet response is appropriate.]
-- Texas Imperial Software | Try WFTPD, the Windows FTP Server. Find us at 1602 Harvest Moon Place | http://www.wftpd.com or email alun@texis.com Cedar Park TX 78613-1419 | VISA/MC accepted. NT-based sites, be sure to Fax/Voice +1(512)258-9858 | read details of WFTPD Pro for XP/2000/NT.
- Next message: Alun Jones: "Re: Privilege-escalation attacks on NT-based Windows are unfixable"
- Previous message: Alun Jones: "Re: TCHAR and buffer overflows"
- In reply to: Edward Elliott: "Re: TCHAR and buffer overflows"
- Next in thread: those who know me have no need of my name: "Re: TCHAR and buffer overflows"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|