|
|||||||||||
|
Re: safe strcpy()?
From: Timo Sirainen <tss(at)iki.fi>
Date: Tue Jan 28 2003 - 23:05:22 EST
On Wed, 2003-01-29 at 05:12, mlh@zip.com.au wrote:
I don't see that much need for C++ once you've gathered yourself a nice set of library functions that allow you to easily do anything you (usually) want. Comparing libc-only code against anything is pretty pointless, it's always uglier and more difficult, but luckily you don't have to limit yourself to it. And I'm not saying that you couldn't write better or at least prettier code with C++, but I think most of the C++ praising is simply about how much better libstdc++ is than libc. Only thing from C++ that I'd actually like to see in C is classes, they're a bit kludgy to implement with structs. > int max = 20;
Looks like an exploitable integer overflow there with 64bit systems. > int main()
How much data can you write into name? Can you set a limit? Is there a default limit? How do you check if the limit was reached and result had to be truncated? What would the code look like with such checks? For such a simple example it might not matter, but it would for any real code. For comparing, here's how the above would be done with my library, with full error checking. It may not be as pretty as you could get it with C++, but I wouldn't say it's bad either. #include } Received on Wed Jan 29 16:04:51 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:02:46 EDT |
||||||||||
|
|||||||||||