Opened 12 years ago

Closed 12 years ago

#1610 closed bug (fixed)

Error opening an empty file

Reported by: humdinger Owned by: stippi
Priority: normal Milestone: R1
Component: Applications/StyledEdit Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

This is on hrev22860 in vmware. Opening an empty file shows this error: "Error loading "[filename]": Bad argument type passed to function". Bummer. Dismissing this alertbox opens the file nontheless.

Attachments (2)

stxt-fix.patch (337 bytes ) - added by vzsolt 12 years ago.
Fix for the STXT translator (without the extra newline)
stxt-fix-nullbytes.patch (1.2 KB ) - added by vzsolt 12 years ago.
A patch separating the (nBytes == 0) condition.

Download all attachments as: .zip

Change History (9)

comment:1 by vzsolt, 12 years ago

There's more to it!

StyledEdit also fails to load files with only 1 character in them. I've traced it, and the bug seems to show up in BTranslationUtils::GetStyledText, where the following call fails: (src/kits/translation/TranslationUtils.cpp, line 345)

	BMallocIO mallocIO;
	if (roster->Translate(source, NULL, &config, &mallocIO,
			B_STYLED_TEXT_FORMAT) < B_OK)
		return B_BAD_TYPE;

by vzsolt, 12 years ago

Attachment: stxt-fix.patch added

Fix for the STXT translator (without the extra newline)

comment:2 by vzsolt, 12 years ago

It turns out that it was caused by the STXT translator, the file_ascmagic function threw away the file if it's size was 0 or 1 bytes, even if the file's type was identified.

I removed that line, now it works as it should.

comment:3 by humdinger, 12 years ago

Thanks for that quick fix, Váradi! If only we could find someone to apply the patch... :) wink,wink, nudge,nudge

comment:4 by stippi, 12 years ago

Owner: changed from korli to stippi
Status: newassigned

comment:5 by stippi, 12 years ago

Resolution: fixed
Status: assignedclosed

I didn't apply the patch quite as is, but I assume the bug it now fixed. :-) Thanks for investigating it! Fixed in hrev22892.

comment:6 by vzsolt, 12 years ago

Resolution: fixed
Status: closedreopened

Thanks for working on it, but the bug is still there.

I did the following:

 ~> touch Text
 ~> StyledEdit Text

And the popup is still there. However, if the file is 1 byte long, it works now :)

The function looks_ascii(...) returns true for the empty buffer, so the second condition won't even be evaluated.

I'm attaching a patch that separates the null bytes condition, and defaults it to UTF-8. Now it really works as it should.

by vzsolt, 12 years ago

Attachment: stxt-fix-nullbytes.patch added

A patch separating the (nBytes == 0) condition.

comment:7 by stippi, 12 years ago

Resolution: fixed
Status: reopenedclosed

Thanks again for checking! Applied your patch in hrev22895.

Note: See TracTickets for help on using tickets.