🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14043

wrong reading of struct members

#14043
From: ferran
Date: Sat, 06 Sep 2003 21:31
64 lines
3134 bytes
Hi I'm trying to write a mp3 tab reader, at the moment I'm writting
the id3v1 class, but C++ Builder doesn't want me to reach my goal.

I have declared the next struct where the mp3 tag info is readed from
file

//----------------------------------
typedef struct
{
    char Header  [3];
    char Title   [30];
    char Artist  [30];
    char Album   [30];
    char Year    [4];
    char Comment [30];
    byte Genre;
} Tid3v1;
//----------------------------------

and to read the tag it I do the next:

//----------------------------------
long   iFileHandle;
Tid3v1 oTMPTag;

iFileHandle = FileOpen(FileName, fmOpenRead);
FileSeek(iFileHandle, -128, 2);
FileRead(iFileHandle, &oTMPTag, 128);
FileClose(iFileHandle);
//----------------------------------

It seemed to work perfectly but then testing I found an mp3 with
comments, and C++ Builder showed a very odd behaviour. This it what is
happening...

This is the Tag output in the Evaluate window for the whole oTMPTag:

//----------------------------------
{ "TAG", "Starlight (Radio Edit)\0\0\0\0\0\0\0\0", "The Supermen
Lovers\0\0\0\0\0\0\0\0\0\0\0",
"Starlight\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", "2001", "CD
Single\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x01', '\x03' }
//----------------------------------

As you can see the year an the comment are clearly delimited in their
variables, but if I try to store the year into an AnsiString (or
anywhere) what oTMPTag.Year returns me is "2001CD Single"!!!!, if I
check in the inspector the object tab again it shows correct ("2001")
but if I move the cursor over oTMPTag.Year again displays "2001CD
Single" instead of only "2001"... and the year is only 4 chars long.
 I though I had a data aligment problem but I already tried the
'pragma pack', didn't fix anything.

I also noticed that if ththis only happens if the members of the
struct do not delimit between them with a '\0', for the aove example
two members are returned wrong:
             oTMPTag.Tag  = "TAGStarlight (Radio Edit)"
             oTMPTag.Year = "2001CDSingle"

I though about reading the contents by fixed size and that would work
but I'm more interested in why C++ Builder returns the wrong values.
Has anyone ecountered a similar problem when reading structs?

<>Thankyou for your help
Technical Details
Message-ID: <53c5c460.0309061331.4f64d19c@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e9d27a5ba7fb557f,start
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-09-06 14:31:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: ferran9@yahoo.com (ferran)
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: wrong reading of struct members
Date: 6 Sep 2003 14:31:41 -0700
Organization: http://groups.google.com/
Lines: 64
Message-ID: <53c5c460.0309061331.4f64d19c@posting.google.com>
NNTP-Posting-Host: 82.35.35.179
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1062883901 18052 127.0.0.1 (6 Sep 2003 21:31:41 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 6 Sep 2003 21:31:41 GMT