X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=ext%2Fvcedit.c;h=fd89008587c452b23db169e16c5435cc1a88593f;hb=e517c533f959a75908b7361b1969146d29cdfa02;hp=832f417b2b30519cba6661b3dfb063c52a43f925;hpb=b1c729d53273c482052dfc99e197463b123e389e;p=ruby-vorbistagger.git diff --git a/ext/vcedit.c b/ext/vcedit.c index 832f417..fd89008 100644 --- a/ext/vcedit.c +++ b/ext/vcedit.c @@ -40,8 +40,6 @@ struct vcedit_state_St { vorbis_comment vc; vorbis_info vi; - char filename[PATH_MAX]; - FILE *in; bool opened; long serial; @@ -53,6 +51,8 @@ struct vcedit_state_St { int prevW; int extrapage; int eosin; + + char filename[0]; }; static void @@ -71,10 +71,12 @@ vcedit_state_free (vcedit_state *state) } static bool -vcedit_state_init (vcedit_state *state) +vcedit_state_init (vcedit_state *state, const char *filename) { state->refcount = 1; + strcpy (state->filename, filename); + return true; } @@ -82,21 +84,23 @@ vcedit_state * vcedit_state_new (const char *filename) { vcedit_state *state; + size_t len; - state = malloc (sizeof (vcedit_state)); + len = strlen (filename); + if (len > PATH_MAX) + return NULL; + + state = malloc (sizeof (vcedit_state) + len + 1); if (!state) return NULL; memset (state, 0, sizeof (vcedit_state)); - if (!vcedit_state_init (state)) { + if (!vcedit_state_init (state, filename)) { vcedit_state_free (state); return NULL; } - snprintf (state->filename, sizeof (state->filename), - "%s", filename); - return state; }