[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

audiofile: FTBFS on hurd-i386 (for review)



Source: audiofile
Version: 0.3.6-2
Severity: important
Tags: patch
User: debian-hurd@lists.debian.org
Usertags: hurd

Hi,

Currently audiofile fails to build from source due to usage of
PATH_MAX, which is not defined on GNU/Hurd. The attached patch solve
this problem by dynamically allocating space for the string 'path' in
function createTemporaryFile() of test/TestUtilities.cpp and freeing it
in the calling functions when not needed any longer. All 36 tests needed
for the build pass.

Thanks!
Index: audiofile-0.3.6/test/TestUtilities.h
===================================================================
--- audiofile-0.3.6.orig/test/TestUtilities.h
+++ audiofile-0.3.6/test/TestUtilities.h
@@ -53,7 +53,7 @@ extern "C" {
 
 #include <stdbool.h>
 
-bool createTemporaryFile(const char *prefix, char *path);
+bool createTemporaryFile(const char *prefix, char **path);
 
 #ifdef __cplusplus
 }
Index: audiofile-0.3.6/test/TestUtilities.cpp
===================================================================
--- audiofile-0.3.6.orig/test/TestUtilities.cpp
+++ audiofile-0.3.6/test/TestUtilities.cpp
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 
 bool createTemporaryFile(const std::string &prefix, std::string *path)
 {
@@ -35,10 +36,14 @@ bool createTemporaryFile(const std::stri
 	return true;
 }
 
-bool createTemporaryFile(const char *prefix, char *path)
+bool createTemporaryFile(const char *prefix, char **path)
 {
-	snprintf(path, PATH_MAX, "/tmp/%s-XXXXXX", prefix);
-	int fd = ::mkstemp(path);
+	int len = 5 + strlen(prefix) + 7 + 1; 
+	*path = (char*)malloc(len);
+	if (*path == NULL)
+		return false;
+	snprintf(*path, len, "/tmp/%s-XXXXXX", prefix);
+	int fd = ::mkstemp(*path);
 	if (fd < 0)
 		return false;
 	::close(fd);
Index: audiofile-0.3.6/test/floatto24.c
===================================================================
--- audiofile-0.3.6.orig/test/floatto24.c
+++ audiofile-0.3.6/test/floatto24.c
@@ -86,8 +86,9 @@ int main (int argc, char **argv)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_FLOAT, 32);
 
-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("floatto24", testFileName))
+	/* testFilename is malloced in createTemporaryFile() */
+	char *testFileName = NULL;
+	if (!createTemporaryFile("floatto24", &testFileName))
 	{
 		fprintf(stderr, "Could not create temporary file.\n");
 		exit(EXIT_FAILURE);
@@ -182,6 +183,7 @@ int main (int argc, char **argv)
 	}
 
 	unlink(testFileName);
+	free(testFileName);
 
 	exit(EXIT_SUCCESS);
 }
Index: audiofile-0.3.6/test/sixteen-to-eight.c
===================================================================
--- audiofile-0.3.6.orig/test/sixteen-to-eight.c
+++ audiofile-0.3.6/test/sixteen-to-eight.c
@@ -57,8 +57,9 @@ int main (int argc, char **argv)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_UNSIGNED, 8);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 
-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("sixteen-to-eight", testFileName))
+	/* testFilename is malloced in createTemporaryFile() */
+	char *testFileName = NULL;
+	if (!createTemporaryFile("sixteen-to-eight", &testFileName))
 	{
 		fprintf(stderr, "Could not create temporary file.\n");
 		exit(EXIT_FAILURE);
@@ -113,6 +114,7 @@ int main (int argc, char **argv)
 
 	afCloseFile(file);
 	unlink(testFileName);
+	free(testFileName);
 
 	exit(EXIT_SUCCESS);
 }
Index: audiofile-0.3.6/test/testchannelmatrix.c
===================================================================
--- audiofile-0.3.6.orig/test/testchannelmatrix.c
+++ audiofile-0.3.6/test/testchannelmatrix.c
@@ -39,7 +39,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 const short samples[] = {300, -300, 515, -515, 2315, -2315, 9154, -9154};
 #define SAMPLE_COUNT (sizeof (samples) / sizeof (short))
@@ -48,6 +49,7 @@ const short samples[] = {300, -300, 515,
 void cleanup (void)
 {
 	unlink(sTestFileName);
+	free(sTestFileName);
 }
 
 void ensure (int condition, const char *message)
@@ -76,7 +78,7 @@ int main (void)
 	afInitFileFormat(setup, AF_FILE_AIFFC);
 
 	/* Write stereo data to test file. */
-	ensure(createTemporaryFile("testchannelmatrix", sTestFileName),
+	ensure(createTemporaryFile("testchannelmatrix", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
Index: audiofile-0.3.6/test/testdouble.c
===================================================================
--- audiofile-0.3.6.orig/test/testdouble.c
+++ audiofile-0.3.6/test/testdouble.c
@@ -38,7 +38,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 const double samples[] =
 	{1.0, 0.6, -0.3, 0.95, 0.2, -0.6, 0.9, 0.4, -0.22, 0.125, 0.1, -0.4};
@@ -49,6 +50,7 @@ void testdouble (int fileFormat);
 void cleanup (void)
 {
 	unlink(sTestFileName);
+	free(sTestFileName);
 }
 
 void ensure (int condition, const char *message)
@@ -96,7 +98,7 @@ void testdouble (int fileFormat)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_DOUBLE, 64);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 2);
 
-	ensure(createTemporaryFile("testdouble", sTestFileName),
+	ensure(createTemporaryFile("testdouble", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
Index: audiofile-0.3.6/test/testfloat.c
===================================================================
--- audiofile-0.3.6.orig/test/testfloat.c
+++ audiofile-0.3.6/test/testfloat.c
@@ -38,7 +38,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 const float samples[] =
 	{1.0, 0.6, -0.3, 0.95, 0.2, -0.6, 0.9, 0.4, -0.22, 0.125, 0.1, -0.4};
@@ -49,6 +50,7 @@ void testfloat (int fileFormat);
 void cleanup (void)
 {
 	unlink(sTestFileName);
+	free(sTestFileName);
 }
 
 void ensure (int condition, const char *message)
@@ -96,7 +98,7 @@ void testfloat (int fileFormat)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_FLOAT, 32);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 2);
 
-	ensure(createTemporaryFile("testfloat", sTestFileName),
+	ensure(createTemporaryFile("testfloat", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "could not open file for writing");
Index: audiofile-0.3.6/test/testmarkers.c
===================================================================
--- audiofile-0.3.6.orig/test/testmarkers.c
+++ audiofile-0.3.6/test/testmarkers.c
@@ -32,7 +32,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 #define FRAME_COUNT 200
 
@@ -40,6 +41,7 @@ void cleanup (void)
 {
 #ifndef DEBUG
 	unlink(sTestFileName);
+	free(sTestFileName);
 #endif
 }
 
@@ -127,7 +129,7 @@ int testmarkers (int fileformat)
 
 int main (void)
 {
-	ensure(createTemporaryFile("testmarkers", sTestFileName),
+	ensure(createTemporaryFile("testmarkers", &sTestFileName),
 		"could not create temporary file");
 
 	testmarkers(AF_FILE_AIFF);
Index: audiofile-0.3.6/test/twentyfour.c
===================================================================
--- audiofile-0.3.6.orig/test/twentyfour.c
+++ audiofile-0.3.6/test/twentyfour.c
@@ -71,8 +71,9 @@ int main (int argc, char **argv)
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 24);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 
-	char testFileName[PATH_MAX];
-	if (!createTemporaryFile("twentyfour", testFileName))
+	/* testFilename is malloced in createTemporaryFile() */
+	char *testFileName = NULL;
+	if (!createTemporaryFile("twentyfour", &testFileName))
 	{
 		fprintf(stderr, "could not create temporary file\n");
 		exit(EXIT_FAILURE);
@@ -239,6 +240,7 @@ int main (int argc, char **argv)
 		exit(EXIT_FAILURE);
 	}
 	unlink(testFileName);
+	free(testFileName);
 
 	exit(EXIT_SUCCESS);
 }
Index: audiofile-0.3.6/test/twentyfour2.c
===================================================================
--- audiofile-0.3.6.orig/test/twentyfour2.c
+++ audiofile-0.3.6/test/twentyfour2.c
@@ -45,7 +45,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 #define FRAME_COUNT 10000
 
@@ -53,6 +54,7 @@ void cleanup (void)
 {
 #ifndef DEBUG
 	unlink(sTestFileName);
+	free(sTestFileName);
 #endif
 }
 
@@ -78,7 +80,7 @@ int main (void)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 24);
 
-	ensure(createTemporaryFile("twentyfour2", sTestFileName),
+	ensure(createTemporaryFile("twentyfour2", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != NULL, "could not open test file for writing");
Index: audiofile-0.3.6/test/writealaw.c
===================================================================
--- audiofile-0.3.6.orig/test/writealaw.c
+++ audiofile-0.3.6/test/writealaw.c
@@ -53,7 +53,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 #define FRAME_COUNT 16
 #define SAMPLE_COUNT FRAME_COUNT
@@ -64,6 +65,7 @@ void cleanup (void)
 {
 #ifndef DEBUG
 	unlink(sTestFileName);
+	free(sTestFileName);
 #endif
 }
 
@@ -113,7 +115,7 @@ void testalaw (int fileFormat)
 	afInitFileFormat(setup, fileFormat);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 
-	ensure(createTemporaryFile("writealaw", sTestFileName),
+	ensure(createTemporaryFile("writealaw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	afFreeFileSetup(setup);
Index: audiofile-0.3.6/test/writeraw.c
===================================================================
--- audiofile-0.3.6.orig/test/writeraw.c
+++ audiofile-0.3.6/test/writeraw.c
@@ -44,12 +44,14 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 void cleanup (void)
 {
 #ifndef DEBUG
 	unlink(sTestFileName);
+	free(sTestFileName);
 #endif
 }
 
@@ -84,7 +86,7 @@ int main (int argc, char **argv)
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 	afInitSampleFormat(setup, AF_DEFAULT_TRACK, AF_SAMPFMT_TWOSCOMP, 16);
 
-	ensure(createTemporaryFile("writeraw", sTestFileName),
+	ensure(createTemporaryFile("writeraw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	ensure(file != AF_NULL_FILEHANDLE, "unable to open file for writing");
Index: audiofile-0.3.6/test/writeulaw.c
===================================================================
--- audiofile-0.3.6.orig/test/writeulaw.c
+++ audiofile-0.3.6/test/writeulaw.c
@@ -53,7 +53,8 @@
 
 #include "TestUtilities.h"
 
-static char sTestFileName[PATH_MAX];
+/* sTestFilename is malloced in createTemporaryFile() */
+static char *sTestFileName = NULL;
 
 #define FRAME_COUNT 16
 #define SAMPLE_COUNT FRAME_COUNT
@@ -64,6 +65,7 @@ void cleanup (void)
 {
 #ifndef DEBUG
 	unlink(sTestFileName);
+	free(sTestFileName);
 #endif
 }
 
@@ -113,7 +115,7 @@ void testulaw (int fileFormat)
 	afInitFileFormat(setup, fileFormat);
 	afInitChannels(setup, AF_DEFAULT_TRACK, 1);
 
-	ensure(createTemporaryFile("writeulaw", sTestFileName),
+	ensure(createTemporaryFile("writeulaw", &sTestFileName),
 		"could not create temporary file");
 	file = afOpenFile(sTestFileName, "w", setup);
 	afFreeFileSetup(setup);

Reply to: