* Matthias Kilian <k...@outback.escape.de> [2009-04-05 13:20]: > On Sun, Apr 05, 2009 at 12:43:07PM -0600, Bob Beck wrote: > > Someone please have a look, and either commit it or tell me to. > > If you add the following patch to the port's makefile, it's ok: > > Ok, how's this.. changed a bit anyway, so we use arc4random_uniform
Index: Makefile =================================================================== RCS file: /cvs/ports/audio/mpd/Makefile,v retrieving revision 1.16 diff -u -r1.16 Makefile --- Makefile 28 Oct 2008 15:21:48 -0000 1.16 +++ Makefile 6 Apr 2009 15:09:54 -0000 @@ -2,7 +2,7 @@ COMMENT= Music Player Daemon DISTNAME= mpd-0.13.2 -PKGNAME= ${DISTNAME}p2 +PKGNAME= ${DISTNAME}p3 CATEGORIES= audio HOMEPAGE= http://www.musicpd.org/ MAINTAINER= Tobias Ulmer <tobi...@tmux.org> Index: patches/patch-src_playlist_c =================================================================== RCS file: patches/patch-src_playlist_c diff -N patches/patch-src_playlist_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-src_playlist_c 6 Apr 2009 15:09:54 -0000 @@ -0,0 +1,80 @@ +--- src/playlist.c.orig Fri Jun 13 22:16:16 2008 ++++ src/playlist.c Mon Apr 6 08:57:25 2009 +@@ -77,6 +77,13 @@ + static int playPlaylistOrderNumber(int fd, int orderNum); + static void randomizeOrder(int start, int end); + ++#ifdef __OpenBSD__ ++#define RANDOM_UB(n) (arc4random_uniform(n)) ++#else ++#define RANDOM_UB(n) (random() % (n)) ++#endif ++ ++ + static void incrPlaylistVersion(void) + { + static unsigned long max = ((mpd_uint32) 1 << 31) - 1; +@@ -647,7 +654,7 @@ + else + start = playlist.current + 1; + if (start < playlist.length) { +- swap = random() % (playlist.length - start); ++ swap = RANDOM_UB(playlist.length - start); + swap += start; + swapOrder(playlist.length - 1, swap); + } +@@ -1189,15 +1196,23 @@ + } + } + +- for (i = start; i <= end; i++) { +- ri = random() % (end - start + 1) + start; +- if (ri == playlist.current) +- playlist.current = i; +- else if (i == playlist.current) +- playlist.current = ri; +- swapOrder(i, ri); ++ /* ++ * Shuffle the Order. ++ * Use an unbiased Fisher-Yates shuffle. ++ */ ++ i = end + 1; ++ while (i > start + 1) { ++ ri = RANDOM_UB(i - start); /* 0 <= ri <= len */ ++ ri += start; ++ i--; /* i is now the last pertinent index */ ++ if (i != ri) { /* do nothing if i == ri */ ++ if (ri == playlist.current) ++ playlist.current = i; ++ else if (i == playlist.current) ++ playlist.current = ri; ++ swapOrder(i, ri); ++ } + } +- + } + + int setPlaylistRandomStatus(int fd, int status) +@@ -1281,12 +1296,17 @@ + i = 0; + playlist.current = -1; + } +- /* shuffle the rest of the list */ +- for (; i < playlist.length; i++) { +- ri = random() % (playlist.length - 1) + 1; +- swapSongs(i, ri); ++ /* ++ * shuffle the rest of the list ++ * Use an unbiased Fisher-Yates shuffle. ++ */ ++ i = playlist.length; ++ while (i > 1) { ++ ri = RANDOM_UB(i); /* 0 <= ri <= len */ ++ i--; /* i is now the last pertinent index */ ++ if (i != ri) /* do nothing if i == ri */ ++ swapSongs(i, ri); + } +- + incrPlaylistVersion(); + } +