Skip to content

Commit

Permalink
net/xprobe: Fix build with Clang 16 and remove the workaround
Browse files Browse the repository at this point in the history
random_shuffle has bee deprecated in C++14 and removed since C++17. Use shuffle instead.

target.cc:373:3: error: use of undeclared identifier 'random_shuffle'
                random_shuffle(ports.begin(), ports.end());
                ^
5 warnings and 1 error generated.

Tested on:	14.0-CURRENT (1400093)
  • Loading branch information
sunpoet committed Aug 21, 2023
1 parent f1108f0 commit 29873d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 0 additions & 9 deletions net/xprobe/Makefile
Expand Up @@ -14,15 +14,6 @@ LICENSE_FILE= ${WRKSRC}/COPYING
CONFIGURE_ENV= INSTALL=${INSTALL}
GNU_CONFIGURE= yes

.include <bsd.port.options.mk>

.if ${OPSYS} == FreeBSD && ( ${OSVERSION} >= 1400091 || ( ${OSVERSION} >= 1302505 && ${OSVERSION} < 1400000 ))
USES+= llvm:max=15
CC= clang${LLVM_VERSION}
CPP= clang-cpp${LLVM_VERSION}
CXX= clang++${LLVM_VERSION}
.endif

post-patch:
@${REINPLACE_CMD} -e 's|-DBROKEN_BSD||' ${WRKSRC}/libs-external/USI++/src/configure

Expand Down
29 changes: 29 additions & 0 deletions net/xprobe/files/patch-src-target.cc
@@ -0,0 +1,29 @@
--- src/target.cc.orig 2005-07-27 08:38:17 UTC
+++ src/target.cc
@@ -28,6 +28,8 @@
#include "os_matrix.h"
#include "xplib/xplib.h"
#include "log.h"
+#include <algorithm>
+#include <random>

extern Interface *ui;
extern Xprobe_Module_Hdlr *xmh;
@@ -363,6 +365,8 @@ void Port_Range::set_range(u_short a, u_short b) {

int Port_Range::get_next(u_short *port) {
int k, sz=size();
+ std::random_device rd;
+ std::mt19937 g(rd());

if (curr+low > high)
return 1;
@@ -370,7 +373,7 @@ int Port_Range::get_next(u_short *port) {
// initialize
for (k=0; k < sz; k++)
ports.push_back(low + k);
- random_shuffle(ports.begin(), ports.end());
+ std::shuffle(ports.begin(), ports.end(), g);
*port = ports[curr++];
} else
*port = ports[curr++];

0 comments on commit 29873d9

Please sign in to comment.