Skip to content

Commit

Permalink
starplot: add debian patch for startup crash
Browse files Browse the repository at this point in the history
resolves #20221
  • Loading branch information
Johnnynator committed Mar 20, 2020
1 parent 9983656 commit 0de7092
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
84 changes: 84 additions & 0 deletions srcpkgs/starplot/patches/05-startup-crash.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
From f603ddfa6a0eb6fc90bc8f14d0bb010efef975fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= <bernhardu@mailbox.org>
Date: Mon, 8 May 2017 23:05:28 +0200
Subject: Replace c-like qsort with c++-like std::sort.

https://bugs.debian.org/862065
---
src/classes/stararray.cc | 49 +++++++++++++++++-------------------------------
1 file changed, 17 insertions(+), 32 deletions(-)

diff --git a/src/classes/stararray.cc b/src/classes/stararray.cc
index 26cc6a0..72cc856 100644
--- src/classes/stararray.cc
+++ src/classes/stararray.cc
@@ -26,6 +26,7 @@

#define NEED_FULL_NAMES
#include "constellations.h"
+#include <algorithm>

using std::string;
using std::vector;
@@ -167,42 +168,26 @@ typedef struct {

// Next, the function to compare for qsort().

-int compare_function(const void *p, const void *q)
-{
- double x1 = ((const sortable *)p)->xposition;
- double x2 = ((const sortable *)q)->xposition;
- return (x1 - x2 >= 0.0) ? 1 : -1;
-}
+struct sort_class {
+ Rules &rules;
+ sort_class(Rules &r) : rules(r) {};
+ bool operator() (const Star &p, const Star &q)
+ {
+ SolidAngle orientation = rules.ChartOrientation;
+ Vector3 relativeLocation;
+ relativeLocation = p.GetStarXYZ() - rules.ChartLocation;
+ double x1 = relativeLocation.getX() * cos(orientation.getPhi()) + relativeLocation.getY() * sin(orientation.getPhi());
+ relativeLocation = q.GetStarXYZ() - rules.ChartLocation;
+ double x2 = relativeLocation.getX() * cos(orientation.getPhi()) + relativeLocation.getY() * sin(orientation.getPhi());
+ return (x1 - x2 >= 0.0) ? 1 : -1;
+ }
+};

-// Finally, the main function which calls qsort()
+// Finally, the main function which calls std::sort()

void StarArray::Sort()
{
- size_t size = Array.size();
- Vector3 relativeLocation;
- SolidAngle orientation = ArrayRules.ChartOrientation;
- sortable *temparray = new sortable[size];
-
- // Make a temporary array for qsort(), consisting of "sortable" structs
- // which each contain a Star and a position in local coordinates.
- for (size_t i = 0; i < size; i++) {
- relativeLocation = Array[i].GetStarXYZ() - ArrayRules.ChartLocation;
- temparray[i].xposition =
- relativeLocation.getX() * cos(orientation.getPhi())
- + relativeLocation.getY() * sin(orientation.getPhi());
- temparray[i].star = Array[i];
- }
-
- qsort(temparray, size, sizeof(sortable), compare_function);
-
- // Put the sorted temporary array back into the vector
- Array.clear();
- for (size_t i = 0; i < size; i++) {
- temparray[i].star.SetPlace(i+1); // label stars starting at 1
- Array.push_back(temparray[i].star);
- }
-
- delete [] temparray;
+ std::sort(Array.begin(), Array.end(), sort_class(ArrayRules));
return;
}

--
2.11.0

2 changes: 1 addition & 1 deletion srcpkgs/starplot/template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Template file for 'starplot'
pkgname=starplot
version=0.95.5
revision=2
revision=3
build_style=gnu-configure
configure_args="--disable-rpath"
hostmakedepends="pkg-config"
Expand Down

0 comments on commit 0de7092

Please sign in to comment.