Print Page | Close Window

CXTPPropertyGridItemDouble::StringToDouble() fails

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=24518
Printed Date: 03 December 2024 at 1:00pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPPropertyGridItemDouble::StringToDouble() fails
Posted By: fleg
Subject: CXTPPropertyGridItemDouble::StringToDouble() fails
Date Posted: 06 November 2024 at 11:33am
Hi,
I probably found a failure in CXTPPropertyGridItemDouble::StringToDouble() method.
With some value where the string is > 20 char, the value we get  is incorrect.

Example:
with "1.3856932626629e-04" no problem the item shows with precision I asked "-1.3857 E-4"
; but same as negative "-1.3856932626629E-04" (21 chars)
get truncated to 20 chars, so "-1.3856932626629E-0" get converted to "-1.3857" losing the exponent.

Looking at the code (version 24.0.0), this buffer of 20 chars looks suspicious.

    char astring[20];
    WideCharToMultiByte(CP_ACP, 0, strValue, -1, astring, 20, NULL, NULL);
    return (double)atof(astring);

from definition of limit of double that goes from -DBL_MIN to DBL_MAX
DBL_MAX 1.7976931348623158e+308
-DBL_MIN -2.2250738585072014e-308

buffer should be at least 25 chars.
you can reproduce the problem with sample app PropertyGrid.PropertyGrid.exe

Can you consider a fix for next release?

Also, as mentioned here
https://forum.codejock.com/cxtppropertygriditemdoublestringtodouble_topic12540_post42376.html?KW=StringTodouble#42376" rel="nofollow - https://forum.codejock.com/cxtppropertygriditemdoublestringtodouble_topic12540_post42376.html?KW=StringTodouble#42376
It could be good to have this method virtual.

Thanks,



Replies:
Posted By: agontarenko
Date Posted: 21 November 2024 at 4:17am
Hello,

I've increased buffer size to 32.

Regards,
Artem Gontarenko 


Posted By: fleg
Date Posted: 22 November 2024 at 3:30am
Thanks!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net