This fixes an occasional crash when loading files in aqualung. This is a fix to an earlier patch, which was taken from Aqualung's bug tracker.
The reason the previous patch was wrong (at least on OpenBSD), is that wchar_t is int on OpenBSD, but gunichar2 is guint16, so the sizes of the types were incorrect, and when CreateIAPEDecompress was passed a pointer to the wrong type, it would occasionally crash with SIGSEGV. This crash happened even when not loading a mac/ape file, as the decoders are run in order for all files, and are expected to return DECODER_OPEN_BADLIB if they don't handle the type. The patch below fixes the error. Can another developer look at it and let me know I missed anything, or if this is OK? Thanks, Jeremy Index: Makefile =================================================================== RCS file: /cvs/ports/audio/aqualung/Makefile,v retrieving revision 1.41 diff -u -p -u -p -r1.41 Makefile --- Makefile 5 Sep 2015 14:59:34 -0000 1.41 +++ Makefile 2 Nov 2016 23:02:21 -0000 @@ -4,6 +4,7 @@ COMMENT= advanced music player VERSION= 1.0 DISTNAME= aqualung-${VERSION} +REVISION= 0 EPOCH= 0 CATEGORIES= audio Index: patches/patch-src_decoder_dec_mac_cpp =================================================================== RCS file: /cvs/ports/audio/aqualung/patches/patch-src_decoder_dec_mac_cpp,v retrieving revision 1.1 diff -u -p -u -p -r1.1 patch-src_decoder_dec_mac_cpp --- patches/patch-src_decoder_dec_mac_cpp 5 Sep 2015 14:59:34 -0000 1.1 +++ patches/patch-src_decoder_dec_mac_cpp 2 Nov 2016 22:56:27 -0000 @@ -1,29 +1,37 @@ $OpenBSD: patch-src_decoder_dec_mac_cpp,v 1.1 2015/09/05 14:59:34 jeremy Exp $ -Use glib character conversion function instead of MAC library function, -since the function used isn't supported in the mac 3.99 version we -have in ports. Taken from a patch in Aqualung Mantis bug #191. +CAPECharacterHelper::GetUTF16FromANSI no longer is included in the +mac library, so roll out own wide character conversion for the +filename. ---- src/decoder/dec_mac.cpp.orig Sun Apr 19 05:49:49 2015 -+++ src/decoder/dec_mac.cpp Sun Aug 30 13:19:54 2015 +--- src/decoder/dec_mac.cpp.orig Sun Apr 19 14:49:49 2015 ++++ src/decoder/dec_mac.cpp Wed Nov 2 23:56:18 2016 @@ -24,6 +24,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -+#include <glib.h> ++#include <wchar.h> /* expand this to nothing so there's no error when including MACLib.h */ -@@ -174,9 +175,9 @@ mac_decoder_open(decoder_t * dec, char * filename) { +@@ -174,9 +175,17 @@ mac_decoder_open(decoder_t * dec, char * filename) { int ret = 0; - wchar_t * pUTF16 = CAPECharacterHelper::GetUTF16FromANSI(filename); - pdecompress = CreateIAPEDecompress(pUTF16, &ret); - free(pUTF16); -+ gunichar2 * pUTF16 = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); -+ pdecompress = CreateIAPEDecompress((wchar_t *)pUTF16, &ret); -+ g_free(pUTF16); ++ wchar_t *wc_filename = (wchar_t *)calloc(sizeof(wchar_t), strlen(filename)+1); ++ if (wc_filename == NULL) { ++ return DECODER_OPEN_BADLIB; ++ } ++ ++ if (mbstowcs(wc_filename, filename, strlen(filename)) == 0) { ++ return DECODER_OPEN_BADLIB; ++ } ++ ++ pdecompress = CreateIAPEDecompress(wc_filename, &ret); ++ free(wc_filename); if (!pdecompress || ret != ERROR_SUCCESS) { return DECODER_OPEN_BADLIB;