Click here to Skip to main content
15,914,160 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: zoom-in & zoom-out Pin
laiju20-Apr-05 20:37
laiju20-Apr-05 20:37 
GeneralRe: zoom-in & zoom-out Pin
Christian Graus21-Apr-05 12:55
protectorChristian Graus21-Apr-05 12:55 
GeneralRe: zoom-in & zoom-out Pin
cmk20-Apr-05 22:39
cmk20-Apr-05 22:39 
Generalconvert string to double using strtod() Pin
nehathoma20-Apr-05 20:09
nehathoma20-Apr-05 20:09 
GeneralRe: convert string to double using strtod() Pin
Christian Graus20-Apr-05 20:27
protectorChristian Graus20-Apr-05 20:27 
GeneralRe: convert string to double using strtod() Pin
nehathoma20-Apr-05 20:47
nehathoma20-Apr-05 20:47 
GeneralRe: convert string to double using strtod() Pin
eli1502197920-Apr-05 21:48
eli1502197920-Apr-05 21:48 
GeneralRe: convert string to double using strtod() Pin
James R. Twine21-Apr-05 2:09
James R. Twine21-Apr-05 2:09 
eli15021979 wrote:
CString string;   <br />
char    *temp;   <br />
double  dNumber;   <br />
temp = string.GetBuffer(string.GetLength());   <br />
sprintf(temp,"%f",dNumber);


   Well, using your code exactly as shown is incorrect because [1] the string has no contents, so calling CString::GetLength() to size the returned buffer is incorrect, [2] you did not call CString::ReleaseBuffer() to relock the written-to buffer, and [3] you did not enforce the length of the data written to the buffer (memory overrun potential).

   (Mis)using CString:
<br />
CString string;   <br />
char    *temp = string.GetBuffer( 32 + 1 );   <br />
double  dNumber = 12345.54321;   <br />
<br />
_snprintf( temp, 32, "%f", dNumber );   // Format Value, Enforce Length<br />
temp[ 32 ] = '\0';                      // Enforce Proper NUL Termination<br />
string.ReleaseBuffer();                 // Return Control Of Buffer To CString<br />

   You will want to add proper exception handling and testing of the pointer returned by CString::ReleaseBuffer().

   Peace!

-=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites
(Please rate this post!)
GeneralRe: convert string to double using strtod() Pin
eli1502197921-Apr-05 2:57
eli1502197921-Apr-05 2:57 
GeneralRe: convert string to double using strtod() Pin
James R. Twine21-Apr-05 4:21
James R. Twine21-Apr-05 4:21 
GeneralRe: convert string to double using strtod() Pin
Christian Graus21-Apr-05 12:56
protectorChristian Graus21-Apr-05 12:56 
GeneralRe: convert string to double using strtod() Pin
ThatsAlok20-Apr-05 21:42
ThatsAlok20-Apr-05 21:42 
GeneralRe: convert string to double using strtod() Pin
nehathoma20-Apr-05 22:19
nehathoma20-Apr-05 22:19 
GeneralRe: convert string to double using strtod() Pin
Chris Losinger21-Apr-05 1:37
professionalChris Losinger21-Apr-05 1:37 
QuestionHow to prevent others to stop my service? Pin
sharkmouse20-Apr-05 19:23
sharkmouse20-Apr-05 19:23 
AnswerRe: How to prevent others to stop my service? Pin
cmk20-Apr-05 22:53
cmk20-Apr-05 22:53 
GeneralSoft Modems Pin
TOMCAT8120-Apr-05 19:11
TOMCAT8120-Apr-05 19:11 
GeneralLog File.. Pin
mpallavi20-Apr-05 18:59
mpallavi20-Apr-05 18:59 
GeneralRe: Log File.. Pin
Christian Graus20-Apr-05 20:29
protectorChristian Graus20-Apr-05 20:29 
GeneralRe: Log File.. Pin
mpallavi20-Apr-05 20:41
mpallavi20-Apr-05 20:41 
GeneralRe: Log File.. Pin
PJ Arends21-Apr-05 7:16
professionalPJ Arends21-Apr-05 7:16 
Generalscrolling MDI CHILD windows Pin
laiju20-Apr-05 18:24
laiju20-Apr-05 18:24 
GeneralHelp Immediate for refreshing screen Pin
popo8420-Apr-05 16:05
popo8420-Apr-05 16:05 
GeneralRe: Help Immediate for refreshing screen Pin
oustar20-Apr-05 17:56
oustar20-Apr-05 17:56 
GeneralDisabling Spell Checker Pin
rjnl20-Apr-05 15:50
rjnl20-Apr-05 15:50 

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.