Opened 8 years ago

Closed 8 years ago

#7760 closed bug (invalid)

BString Constructor with negative maxLength arg should copy entire string.

Reported by: jscipione Owned by: axeld
Priority: normal Milestone: R1
Component: Kits/Support Kit Version: R1/Development
Keywords: BString Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

I ran the following program in Haiku and BeOS R5.

#include <String.h>
#include <stdio.h>

int main(void)
{
	BString string1 = BString("string 1");
	printf("String 1 is: %s\n", string1.String());

	BString string2 = BString("string 2", 100);
	printf("String 2 is: %s\n", string2.String());
	
	BString string3 = BString("string 3", 0);
	printf("String 3 is: %s\n", string3.String());
	
	BString string4 = BString("string 4", -1);
	printf("String 4 is: %s\n", string4.String());

	return 0;
}

In Haiku I get:

String 1 is: string1

String 2 is: string2

String 3 is:

String 4 is:

In BeOS R5 I get:

String 1 is: string1

String 2 is: string2

String 3 is:

String 4 is: string4

So there is an incompatibility that should be fixed. The BString constructor with a negative maxLength argument should return the entire string, not a blank string.

Attachments (1)

stringtest.png (56.4 KB) - added by jscipione 8 years ago.
Screenshot of program in BeOS R5 demonstrating the incompatability

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by jscipione

Attachment: stringtest.png added

Screenshot of program in BeOS R5 demonstrating the incompatability

comment:1 Changed 8 years ago by axeld

Dano even crashes at "String 4". Since this behavior is not documented at all, and obviously not even working in all BeOS versions, I would be inclined to live with that deviation.

comment:2 in reply to:  1 Changed 8 years ago by jscipione

Replying to axeld:

Dano even crashes at "String 4". Since this behavior is not documented at all, and obviously not even working in all BeOS versions, I would be inclined to live with that deviation.

I would be okay with closing this bug with status WONTFIX. A note in the Haiku Book in the BString() constructor could be helpful though.

comment:3 Changed 8 years ago by jscipione

Resolution: invalid
Status: newclosed

A note indicating the inconsistency between the BeOS R5 and Haiku BString contructor when a negative maxLength argument is passed in has been added to the Haiku Book. We don't want to copy BeOS R5 in this instance since the functionality was not consistent across BeOS releases anyway.

Note: See TracTickets for help on using tickets.