From 24fb5ed32c27af1ec32afc42867c2681fef45b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 29 Sep 2010 09:47:36 +0000 Subject: [PATCH] * Initializing "id", and "track" to zero in r37310 caused a bug in read_cdtext() to be revealed, as both variables were not supposed to change between calls to parse_pack_data(). This could cause an invalidation of the CD-text data, as well as an endless loop. * Disabled (and improved) some more debug output. * Added a short description to parse_pack_data(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38844 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/cdda/cdda.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/cdda/cdda.cpp b/src/add-ons/kernel/file_systems/cdda/cdda.cpp index 8f19c4de18..90beaf6ba8 100644 --- a/src/add-ons/kernel/file_systems/cdda/cdda.cpp +++ b/src/add-ons/kernel/file_systems/cdda/cdda.cpp @@ -285,6 +285,13 @@ is_string_id(uint8 id) } +/*! Parses a \a pack data into the provided text buffer; the corresponding + track number will be left in \a track, and the type of the data in \a id. + The pack data is explained in SCSI MMC-3. + + \a id, \a track, and \a state must stay constant between calls to this + function. \a state must be initialized to zero for the first call. +*/ static bool parse_pack_data(cdtext_pack_data *&pack, uint32 &packLeft, cdtext_pack_data *&lastPack, uint8 &id, uint8 &track, uint8 &state, @@ -299,6 +306,7 @@ parse_pack_data(cdtext_pack_data *&pack, uint32 &packLeft, if (state != 0) { // we had a terminated string and a missing track track++; + memcpy(buffer, lastPack->text + state, 12 - state); if (pack->track - track == 1) state = 0; @@ -319,12 +327,14 @@ parse_pack_data(cdtext_pack_data *&pack, uint32 &packLeft, } while (id == pack->id && track == pack->track) { -#if 1 +#if 0 dprintf("%u.%u.%u, %u.%u.%u, ", pack->id, pack->track, pack->number, pack->double_byte, pack->block_number, pack->character_position); for (int32 i = 0; i < 12; i++) { if (isprint(pack->text[i])) dprintf("%c", pack->text[i]); + else + dprintf("-"); } dprintf("\n"); #endif @@ -520,11 +530,12 @@ read_cdtext(int fd, struct cdtext &cdtext) cdtext_pack_data *pack = (cdtext_pack_data *)(header + 1); cdtext_pack_data *lastPack = NULL; uint8 state = 0; + uint8 track = 0; + uint8 id = 0; char text[256]; while (true) { size_t length = sizeof(text); - uint8 id = 0, track = 0; if (!parse_pack_data(pack, packLength, lastPack, id, track, state, text, length))