Re: const char * to char[]
From: Richard Bos (rlb_at_hoekstra-uitgeverij.nl)
Date: 11/19/03
- Next message: Al Bowers: "Re: C Array Sort - Pass By Reference........."
- Previous message: Richard Bos: "Re: void pointer arithmetic"
- In reply to: Charles Banas: "Re: const char * to char[]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 19 Nov 2003 14:06:19 GMT
greywolf@the-junkyard.net (Charles Banas) wrote:
> "Allan Bruce" <allanmb@TAKEAWAYf2s.com> wrote in message news:<bpdcht$s0$1@news.freedom2surf.net>...
> > and I attempt to copy my AppName to NOTIFYICONDATA.szTip by:
> > NOTIFYICONDATA TrayIcon; // set structure
> > strncpy(TrayIcon.szTip, mWCS->AppName, 64); // tooltip text to display
Be careful. You happen to know that your string fits now, but consider
what would happen if AppName were exactly 64 characters long, not
including the terminating null character.
> call me naiive, but isn't it possible that the memory beyond the
> string AppName points to could be code memory?
What has that got to do with it?
> strncpy(TrayIcon.szTip, mWCS->AppName, 22);
You are confused about the behaviour of strncpy(), I suspect. It does
_not_ copy exactly N bytes - if it did, you might as well use memcpy().
What it does is copy up to either the end of the string, or N bytes,
whichever comes first. And then, superfluously, pads the rest with null
characters.
Richard
- Next message: Al Bowers: "Re: C Array Sort - Pass By Reference........."
- Previous message: Richard Bos: "Re: void pointer arithmetic"
- In reply to: Charles Banas: "Re: const char * to char[]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|