Tracker: Bugs

5 operator String::(char *) () needs to null-terminate itself - ID: 221685
Last Update: Comment added ( crag )

Since it returns a "char *" which is a C type with no OOB length information, it needs to be null-terminated. New Strings are terminated now, but if you take a slice that ends before the original string ends, the substring isn't null-terminated. This is fine as long as it's a String which has a length(), but when you cast it to char* that information is lost.


Robert de Forest ( crag ) - 2000-11-05 11:50:00 PST

5

Closed

Fixed

Colin McCormack

Feature Request

Request For Enhancement

Public


Comments ( 2 )

Date: 2001-10-15 22:41:51 PDT
Sender: cragProject Admin

Logged In: YES
user_id=23612

Now that String has a nullterm() function, this is taken
care of. For instances when a null-terminated version of a
string is needed, (char*) (str->nullterm()) should be fine.


Date: 2001-01-13 21:46:15 PST
Sender: coldstoreProject Admin

Approach: I'll mod the (char*) casting operator to silently append a null
to the internal extent.

This will entail a copy in the cases:
1) that the String is a sub-slice of another, since the refcount on its
contents will be >1 (by definition)
2) that the String fully occupies its external extent.

Alternative resolution might be so explicitly state that (char*) doesn't
null-terminate, but that's inconvenient and tempts fate (someone one day
will just jam a null at the end, and overwrite a sharing String's content.



Attached File

No Files Currently Attached

Changes ( 4 )

Field Old Value Date By
status_id Open 2001-10-15 22:41:51 PDT crag
resolution_id None 2001-10-15 22:41:51 PDT crag
close_date - 2001-10-15 22:41:51 PDT crag
assigned_to nobody 2001-01-13 17:50:03 PST coldstore