Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Probable nasty bug with StringBuffer
Probable nasty bug with StringBuffer [message #57439] Thu, 12 August 2021 18:07 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
This snippet:
#include <Core/Core.h>

using namespace Upp;

String test()
{
	StringBuffer sb(10);
	sb[0] = 'a';
	sb[1] = 'b';
	sb[2] = 'c';
	sb[3] = 'd';
	sb[4] = 'e';
	sb[5] = 0;
	sb[6] = 'f';
	sb[7] = 'g';
	sb[8] = 'h';
	sb[9] = 'i';
	return sb;
}

CONSOLE_APP_MAIN
{
	String s = test();
	Cerr() << "len(s)=" << s.GetCount() << "\n";
}


prints 10 in Linux with GCC and 5 in windows10 with msvs19 compiler, 32 bit.
Tracing it I found that converting sb to string just before test() return uses strlen(), which obviously
stops at '0' byte in string.
It used to behave correctly before (msvs15 compiler) but now because of a problem in SIMD_SSE2.h I can't compile
with it anymore.
This problem appeared in Cypher bazaar (and also UppHub) package, which make encrypted strings containint '0' bytes to be
truncated.

Ciao

Massimo

p.s.: quick solution is to do a 'return String(sb)' instead of 'return sb', but IMHO this is a dangerous bug, as used way should be correct anyways...

p.p.s.: clang compiler brings correct result.

[Updated on: Thu, 12 August 2021 18:14]

Report message to a moderator

Re: Probable nasty bug with StringBuffer [message #57452 is a reply to message #57439] Thu, 19 August 2021 17:28 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I am getting len(s) = 10 in all circumstances.

What U++ are you on? I remember fixing something possibly related around StringBuffer 1-2 years ago.
Re: Probable nasty bug with StringBuffer [message #57454 is a reply to message #57452] Thu, 19 August 2021 18:36 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1307
Registered: September 2007
Ultimate Contributor
Mhhh... I will re-check. I reinstalled on windows10 (I was on 7 before), but I did an svn update.

I'll double check on next days.

Thank you!

Massimo
Re: Probable nasty bug with StringBuffer [message #57455 is a reply to message #57454] Thu, 19 August 2021 19:11 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mdelfede wrote on Thu, 19 August 2021 18:36
Mhhh... I will re-check. I reinstalled on windows10 (I was on 7 before), but I did an svn update.

I'll double check on next days.

Thank you!

Massimo


Note that svn is now read-only, we moved to github... but that should not affect your problem, that is just recent issue

Mirek
Previous Topic: How do I implement mouse hover in Ctrl based class
Next Topic: Strings with national specific characters are wrongly sorted - Sort
Goto Forum:
  


Current Time: Fri Mar 29 06:33:30 CET 2024

Total time taken to generate the page: 0.01249 seconds