Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thoughts on HCCString.h #1

Open
CodeVisio opened this issue Dec 3, 2024 · 4 comments
Open

Thoughts on HCCString.h #1

CodeVisio opened this issue Dec 3, 2024 · 4 comments

Comments

@CodeVisio
Copy link

CodeVisio commented Dec 3, 2024

Hi,

The explicit keyword on BasicString constructors on line 956
doesn't allow code like this (unless being pedantic):

#define FOO L"foo"
constexpr Core::WideString::CharType * foo = L"foo";

void Bar( const Core::WideString & s ) {...}

later...
{
   Bar( FOO );  // flagged as error, fixed (pedantic) as Bar( Core::WideString( FOO ) );
   Bar( foo ); // flagged as error, fixed (pedantic) as Bar( Core::WideString( foo ) );
}

Constructor at 961 suffers the same problem (imagine Bar( { FOO, _countof( FOO ) } ) )
Compiled with VS2022 community and C++ 20.

Is that by design?

Thanks

Edited

@Harlinn
Copy link
Owner

Harlinn commented Dec 3, 2024

Yes, for now, it's by design. This constructor wasn't explicit to begin with, but ended up in an implicit conversion, causing a bug.
Making it explicit, fixed the problem.

Best regards
Espen Harlinn

@CodeVisio
Copy link
Author

Thank you for your answer.

I've skimmed through the class code (HCCString) and I've noticed some subtleties
but it could be my non-familiar with the class design.
Without building fancy examples you can see one of the subtleties just using the following code:

WideString s;
s.Insert( 0, 1, L'H' );

This should crash.
That's because, following your code, the const iterator is constructed when the inner reference data is not yet allocated, then memove references a null pointer.

Best Regards

@Harlinn
Copy link
Owner

Harlinn commented Dec 5, 2024

Thanks for locating this embarrassing bug, I've reimplemented Insert and added a few unit tests. It was, unfortunately, not covered by the tests. If you find anything else I would certainly like to know :-)

Best regards
Espen Harlinn

@CodeVisio
Copy link
Author

Glad I could help.

Best Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants