From adc1418cbd29794ff4b85ffad59188b7c755b8fc Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 25 Apr 2005 23:06:21 +0000 Subject: [PATCH] From Burkhard Plaum: 1. Fix a crash, which happened when cdtext_get() was called for an emtp= y (i.e. NULL) field. 2. Add another function cdtext_get_const(), which returns a const point= er and avoids too much strcpying (apps may want only to TEST if a field is present or have their own string management routines). --- include/cdio/cdtext.h | 13 ++++++++++++- lib/driver/cdtext.c | 12 ++++++++++-- lib/driver/libcdio.sym | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/cdio/cdtext.h b/include/cdio/cdtext.h index fbd932f7..66369261 100644 --- a/include/cdio/cdtext.h +++ b/include/cdio/cdtext.h @@ -1,5 +1,5 @@ /* - $Id: cdtext.h,v 1.10 2005/01/29 20:54:20 rocky Exp $ + $Id: cdtext.h,v 1.11 2005/04/25 23:06:21 rocky Exp $ Copyright (C) 2004, 2005 Rocky Bernstein adapted from cuetools @@ -85,6 +85,17 @@ extern "C" { input here. */ char *cdtext_get (cdtext_field_t key, const cdtext_t *cdtext); + + /*! returns a const string associated with the given field. NULL is + returned if key is CDTEXT_INVALID or the field is not set. + + Don't use the string when the cdtext object (i.e. the CdIo_t object + you got it from) is no longer valid. + + @see cdio_get_cdtext to retrieve the cdtext structure used as + input here. + */ + const char *cdtext_get_const (cdtext_field_t key, const cdtext_t *cdtext); /*! returns enum of keyword if key is a CD-Text keyword, diff --git a/lib/driver/cdtext.c b/lib/driver/cdtext.c index 4cdc5b43..c6de8219 100644 --- a/lib/driver/cdtext.c +++ b/lib/driver/cdtext.c @@ -1,5 +1,5 @@ /* - $Id: cdtext.c,v 1.4 2005/03/23 11:15:25 rocky Exp $ + $Id: cdtext.c,v 1.5 2005/04/25 23:06:21 rocky Exp $ Copyright (C) 2004, 2005 Rocky Bernstein toc reading routine adapted from cuetools @@ -89,10 +89,18 @@ cdtext_destroy (cdtext_t *p_cdtext) char * cdtext_get (cdtext_field_t key, const cdtext_t *p_cdtext) { - if (key == CDTEXT_INVALID) return NULL; + if ((key == CDTEXT_INVALID) || (!p_cdtext->field[key])) return NULL; return strdup(p_cdtext->field[key]); } +const char * +cdtext_get_const (cdtext_field_t key, const cdtext_t *p_cdtext) +{ + if (key == CDTEXT_INVALID) return NULL; + return p_cdtext->field[key]; +} + + /*! Initialize a new cdtext structure. When the structure is no longer needed, release the resources using cdtext_delete. diff --git a/lib/driver/libcdio.sym b/lib/driver/libcdio.sym index 977b0d23..cd4155cd 100644 --- a/lib/driver/libcdio.sym +++ b/lib/driver/libcdio.sym @@ -158,6 +158,7 @@ cdio_warn cdtext_destroy cdtext_field2str cdtext_get +cdtext_get_const cdtext_init cdtext_is_keyword cdtext_set