Click here to Skip to main content
16,005,389 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMFC application Pin
Mohanraj D15-May-08 23:32
Mohanraj D15-May-08 23:32 
AnswerRe: MFC application Pin
Rajesh R Subramanian15-May-08 23:36
professionalRajesh R Subramanian15-May-08 23:36 
GeneralRe: MFC application Pin
Mohanraj D15-May-08 23:43
Mohanraj D15-May-08 23:43 
GeneralRe: MFC application Pin
Rajesh R Subramanian15-May-08 23:50
professionalRajesh R Subramanian15-May-08 23:50 
GeneralRe: MFC application Pin
Hamid_RT16-May-08 0:19
Hamid_RT16-May-08 0:19 
QuestionCFile read Pin
iayd15-May-08 22:35
iayd15-May-08 22:35 
AnswerRe: CFile read Pin
Dominik Reichl15-May-08 22:42
Dominik Reichl15-May-08 22:42 
AnswerRe: CFile read Pin
Iain Clarke, Warrior Programmer15-May-08 22:46
Iain Clarke, Warrior Programmer15-May-08 22:46 
1/
new char [file.GetLength()];


2/
You are making a buffer exactly as long as the file - and as it's char buffer, you're likely to be expecting it to be NULL terminated. Which it won't be...

Your second example reads *upto* 100 chars, so will probably be less, and as that chunk of 100 bytes probably has a zero or two in it, you get away with it.

Make a text file 100 bytes long, and it would likely fail too.

3/
I'd put the size into a variable, if only for debugging purposes.

4/
You could also have some naughty person save a '\0' somewhere in the file, so your string would be messed up... Especially if this program ends up in the wild. The effect could be benign: "Ok, it will look like there was less text. big deal", or critical, depending on your code.

Iain.

Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

AnswerRe: CFile read Pin
toxcct15-May-08 23:01
toxcct15-May-08 23:01 
GeneralPLEZZZ SIR Pin
Rajesh R Subramanian15-May-08 23:24
professionalRajesh R Subramanian15-May-08 23:24 
GeneralRe: PLEZZZ SIR Pin
toxcct15-May-08 23:43
toxcct15-May-08 23:43 
GeneralRe: PLEZZZ SIR Pin
Rajesh R Subramanian15-May-08 23:48
professionalRajesh R Subramanian15-May-08 23:48 
AnswerRe: CFile read Pin
David Crow16-May-08 5:26
David Crow16-May-08 5:26 
QuestionRegarding CHyperLink example Pin
H4u3215-May-08 21:41
H4u3215-May-08 21:41 
AnswerRe: Regarding CHyperLink example Pin
Iain Clarke, Warrior Programmer16-May-08 0:03
Iain Clarke, Warrior Programmer16-May-08 0:03 
GeneralRe: Regarding CHyperLink example Pin
H4u3216-May-08 0:12
H4u3216-May-08 0:12 
GeneralRe: Regarding CHyperLink example Pin
Iain Clarke, Warrior Programmer16-May-08 0:45
Iain Clarke, Warrior Programmer16-May-08 0:45 
AnswerRe: Regarding CHyperLink example Pin
David Crow16-May-08 5:29
David Crow16-May-08 5:29 
GeneralRe: Regarding CHyperLink example Pin
H4u3217-May-08 1:09
H4u3217-May-08 1:09 
QuestionToolTip Pin
john563215-May-08 21:39
john563215-May-08 21:39 
AnswerRe: ToolTip Pin
Iain Clarke, Warrior Programmer15-May-08 22:50
Iain Clarke, Warrior Programmer15-May-08 22:50 
GeneralRe: ToolTip Pin
john563215-May-08 22:57
john563215-May-08 22:57 
GeneralRe: ToolTip Pin
Iain Clarke, Warrior Programmer15-May-08 23:19
Iain Clarke, Warrior Programmer15-May-08 23:19 
AnswerRe: ToolTip Pin
Hamid_RT15-May-08 23:24
Hamid_RT15-May-08 23:24 
QuestionTemplate Argument Problem Pin
Sarath C15-May-08 21:22
Sarath C15-May-08 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.