Your message dated Sat, 03 Mar 2012 15:47:32 +0000
with message-id <[email protected]>
and subject line Bug#317592: fixed in apt-spy 3.2.2-1
has caused the Debian Bug report #317592,
regarding apt-spy: initialization of defaults can be inlined
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
317592: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=317592
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: apt-spy
Severity: minor
Tags: patch

Initialization of defaults can be inlined.  I see:

  $ grep 'd_.*\[' main.c
  main.c:char d_area[] = "All";
  main.c:char d_out[] = "/etc/apt/sources.list";
  main.c:char d_config[] = "/etc/apt-spy.conf";
  main.c:char d_mirror[] = "/var/lib/apt-spy/mirrors.txt";
  main.c:char d_file[] = "ls-lR";
  main.c:char d_update_url[] = 
"http://http.us.debian.org/debian/README.mirrors.txt";;

and then I see:

  $ for s in $(grep -o 'd_[^[]*\[' main.c |sed -e 's/\[$//'); do echo -n $s; 
grep -h "=.*$s" *.c; done;
  d_area          area = d_area;
  d_out           outfile = d_out;
  d_config                config_file = d_config;
  d_mirror                mirror_list = d_mirror;
  d_file          grab_file = d_file;
  d_update_url                    update_url = d_update_url;

I can't see any reason why these can't all be initialized inline with
their declaration, as in
        
        char *area=d_area;

instead of having it set by a runtime conditional.  If any of those
static default strings don't have corresponding variables in main(),
then you could still initialize them (in an arbitrary function) by
using #defines, as in

        char *foo = FOO_D;

where a new ./includes/defaults.h can specify, in a central location,
all of the FOO_D defaults.

(I believe, however, that each of those 6 static strings have such a
corresponding variable in main).

[ ... ]

I've now written a patch for this.  The only complication is d_area,
which requires a minor code change: since it will always be non-NULL,
the check is now country_list!=NULL.

Justin
Only in apt-spy-3.1.jp: apt-spy
diff -ur apt-spy-3.1/benchmark.c apt-spy-3.1.jp/benchmark.c
--- apt-spy-3.1/benchmark.c     2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp/benchmark.c  2005-07-08 21:45:23.000000000 -0400
@@ -10,6 +10,7 @@
 #include "include/parse.h"
 #include "include/benchmark.h"
 #include "include/protocols.h"
+#include "include/global.h"
 
 /* 
  * It is safer to keep track of the total amount of data read ourselves.
@@ -79,12 +80,12 @@
        /* Inefficient sorting algorithm, but small number of entries so it 
doesn't matter. */
 
        /* move 'i' to the correct place in the array to place the new entry */
-       for (i = 0; i < BESTNUMBER; ++i)
+       for (i = 0; i < bestnumber; ++i)
                if (current->stats.speed > best[i].stats.speed)
                        break;
        
        /* shove everything along one */
-       for (j = BESTNUMBER - 2; j >= i; --j)
+       for (j = bestnumber - 2; j >= i; --j)
                memcpy(&best[j + 1], &best[j], sizeof(server_t));
        
        /* copy the new entry into the correct place */
Only in apt-spy-3.1.jp: build-stamp
Only in apt-spy-3.1.jp: configure-stamp
diff -ur apt-spy-3.1/file.c apt-spy-3.1.jp/file.c
--- apt-spy-3.1/file.c  2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp/file.c       2005-07-09 14:45:56.000000000 -0400
@@ -52,9 +52,6 @@
 {
        FILE *fp;
        
-       if (config_file == NULL)
-               config_file = d_config;
-       
        fp = fopen(config_file, "r");
        
        return fp;
@@ -64,9 +61,6 @@
 {
        FILE *fp;
        
-       if (mirror_list == NULL)
-               mirror_list = d_mirror;
-       
        if (are_updating == 1)
                fp = fopen(mirror_list, "w");
        else
diff -ur apt-spy-3.1/include/global.h apt-spy-3.1.jp/include/global.h
--- apt-spy-3.1/include/global.h        2003-12-18 10:12:24.000000000 -0500
+++ apt-spy-3.1.jp/include/global.h     2005-07-09 17:47:15.000000000 -0400
@@ -3,9 +3,26 @@
 #ifndef __GLOBAL_H
 #define __GLOBAL_H
 
-extern char apt_spy_v[];
-extern char d_out[];
-extern char d_config[];
-extern char d_mirror[];
+/* Defaults values */
+
+/* Our version number. */
+#define        apt_spy_v       "v3.1"
+
+/* The default area */
+#define        D_AREA          "All"
+
+/* Default file locations */
+#define D_OUT           "/etc/apt/sources.list"
+#define D_CONFIG        "/etc/apt-spy.conf"
+#define D_MIRROR        "/var/lib/apt-spy/mirrors.txt"
+
+/* Default file to grab when benchmarking */
+#define D_FILE         "ls-lR"
+
+/* Default update URL */
+#define        D_UPDATE_URL    
"http://http.us.debian.org/debian/README.mirrors.txt";
+
+#define        BESTNUMBER      5
+extern int bestnumber;
 
 #endif
diff -ur apt-spy-3.1/include/parse.h apt-spy-3.1.jp/include/parse.h
--- apt-spy-3.1/include/parse.h 2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp/include/parse.h      2005-07-08 21:06:35.000000000 -0400
@@ -6,9 +6,6 @@
 #define FTP 0
 #define HTTP 1
 
-/* hack */
-extern int BESTNUMBER;
-
 struct stats_struct {
        int protocol;
        double speed;
diff -ur apt-spy-3.1/main.c apt-spy-3.1.jp/main.c
--- apt-spy-3.1/main.c  2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp/main.c       2005-07-09 17:48:19.000000000 -0400
@@ -16,27 +16,9 @@
 #include "include/file.h"
 #include "include/parse.h"
 #include "include/benchmark.h"
+#include "include/global.h"
 
-/* Our version number. */
-const char apt_spy_v[] = "v3.1";
-
-/* Defaults */
-
-/* The default area */
-char d_area[] = "All";
-
-/* Default file locations */
-char d_out[] = "/etc/apt/sources.list";
-char d_config[] = "/etc/apt-spy.conf";
-char d_mirror[] = "/var/lib/apt-spy/mirrors.txt";
-
-/* Default file to grab when benchmarking */
-char d_file[] = "ls-lR";
-
-/* Default update URL */
-char d_update_url[] = "http://http.us.debian.org/debian/README.mirrors.txt";;
-
-int BESTNUMBER = 5;
+int bestnumber=BESTNUMBER;
 
 int main(int argc, char *argv[])
 {
@@ -44,15 +26,15 @@
        char *cur_entry;                /* Entry we are benchmarking */
 
        char *distrib = NULL;           /* distrubtion to use. */
-       char *mirror_list = NULL;       /* mirror list file */
-       char *config_file = NULL;       /* configuraion file */
+       char *mirror_list = D_MIRROR;   /* mirror list file */
+       char *config_file = D_CONFIG;   /* configuraion file */
        char *proxy = NULL;             /* Proxy server to use */
        char *infile = NULL;            /* optional infile */
-       char *outfile = NULL;           /* outfile name */
+       char *outfile = D_OUT;          /* outfile name */
        char *topfile = NULL;
-       char *area = NULL;              /* Area to test */
-       char *grab_file = NULL;         /* File to grab */
-       char *update_url = NULL;        /* URL to use for updating */
+       char *area = strdup(D_AREA);    /* Area to test; modified in 
build_area_file*/
+       char *grab_file = D_FILE;       /* File to grab */
+       char *update_url = D_UPDATE_URL;/* URL to use for updating */
        char *country_list = NULL;      /* List of countries to b/m */
        FILE *infile_p, *outfile_p;     /* input/output file pointers */
        FILE *config_p;                 /* config file pointer */
@@ -126,7 +108,7 @@
                        break;
                /* Number of servers to write in "top" server list */
                case 'n':
-                       BESTNUMBER = atoi(optarg);
+                       bestnumber = atoi(optarg);
                        break;
                case 'v':
                        version();
@@ -141,10 +123,10 @@
        argv += optind;
 
        /* Simple check for stupidity */
-       if ((test_number >= 0) && (BESTNUMBER > test_number))
-               BESTNUMBER = test_number;
+       if ((test_number >= 0) && (bestnumber > test_number))
+               bestnumber = test_number;
 
-       best = malloc(sizeof(server_t) * (BESTNUMBER + 1)); 
+       best = malloc(sizeof(server_t) * (bestnumber + 1)); 
 
        if (best == NULL) {
                perror("malloc");
@@ -156,16 +138,8 @@
                usage();
 
        /* Check for silly combination of country and area arguments */
-       if ((area != NULL) && (country_list != NULL))
-               usage();
-
-       /* Setup default area argument */
-       if ((area == NULL) && (country_list == NULL))
-               area = d_area;
-
-       /* Setup default file argument if none given */
-       if (grab_file == NULL)
-               grab_file = d_file;
+       if (strcmp(area, D_AREA) && (country_list != NULL))
+               usage();
 
        /* Open mirror file. We pass argc so it can tell if we're updating 
           or not */
@@ -182,10 +156,6 @@
                if (strcmp(argv[0], "update") != 0)
                usage();
 
-                /* If necessary, set update_url to default */
-               if (update_url == NULL)
-                       update_url = d_update_url;
-
                if (update(mirror_p, update_url, proxy) != 0) {
                        fprintf(stderr, "Update failed. Exiting.\n");
                        exit(1);
@@ -197,7 +167,6 @@
        /* argc should be 0. If not, there's something wrong. */
        if (argc != 0)
                usage();
-                                       
 
        /* We open the infile. Either a temporary file, or a user-specified 
           one. */
@@ -208,10 +177,6 @@
                exit(1);
        }
 
-       /* Set up default if user hasn't specified an outfile */
-       if (outfile == NULL)
-               outfile = d_out;
-
        /* Check output file for accessibility */
        if (check_write_access(outfile) == 1) {
                fprintf(stderr, "Could not open outfile. Exiting.\n");
@@ -236,18 +201,19 @@
 
        /* Fill temporary file with useful stuff if it's not user-specified. */
        if (infile == NULL) {
-               if (area != NULL) {
-                       if (build_area_file(config_p, infile_p, mirror_p, area) 
!= 0) {
-                               fprintf(stderr, 
-                               "Error building area file. Exiting.\n");
-                               exit(1);
-                       }
-               } else {
+               if (country_list) {
                        if (build_country_file(config_p, infile_p, mirror_p, 
country_list) != 0) {
                                fprintf(stderr,
                                "Error building country file. Exiting.\n");
                                exit(1);
                        }
+
+               } else {
+                       if (build_area_file(config_p, infile_p, mirror_p, area) 
!= 0) {
+                               fprintf(stderr, 
+                               "Error building area file. Exiting.\n");
+                               exit(1);
+                       }
                }
        }
                        
@@ -256,7 +222,7 @@
        rewind(infile_p);
 
        /* Zero the "best" structure */
-       for (c = 0; c < BESTNUMBER; c++)
+       for (c = 0; c < bestnumber; c++)
                memset(&best[c], 0, sizeof(server_t));
 
        /* This is the main loop. It'll exit when we've exhausted the URL 
diff -ur apt-spy-3.1/parse.c apt-spy-3.1.jp/parse.c
--- apt-spy-3.1/parse.c 2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp/parse.c      2005-07-08 21:45:26.000000000 -0400
@@ -359,7 +359,7 @@
        int i = 0;
        char *line;
        
-       while (i < BESTNUMBER) {
+       while (i < bestnumber) {
        
                /* Make sure we're at the beginning */
                rewind(infile_p);
Only in apt-spy-3.1.jp: test

--- End Message ---
--- Begin Message ---
Source: apt-spy
Source-Version: 3.2.2-1

We believe that the bug you reported is fixed in the latest version of
apt-spy, which is due to be installed in the Debian FTP archive:

apt-spy_3.2.2-1.debian.tar.gz
  to main/a/apt-spy/apt-spy_3.2.2-1.debian.tar.gz
apt-spy_3.2.2-1.dsc
  to main/a/apt-spy/apt-spy_3.2.2-1.dsc
apt-spy_3.2.2-1_i386.deb
  to main/a/apt-spy/apt-spy_3.2.2-1_i386.deb
apt-spy_3.2.2.orig.tar.gz
  to main/a/apt-spy/apt-spy_3.2.2.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to [email protected],
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Stefano Canepa <[email protected]> (supplier of updated apt-spy package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing [email protected])


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 14 Jan 2012 00:02:21 +0100
Source: apt-spy
Binary: apt-spy
Architecture: source i386
Version: 3.2.2-1
Distribution: unstable
Urgency: low
Maintainer: Stefano Canepa <[email protected]>
Changed-By: Stefano Canepa <[email protected]>
Description: 
 apt-spy    - writes a sources.list file based on bandwidth tests
Closes: 317592 320112 447232 457049 491802 548591 551344 617699 645839 645910
Changes: 
 apt-spy (3.2.2-1) unstable; urgency=low
 .
   * New upstream release
    - Fixes segfault with option -m and special args (Closes: #645839)
    - Fixes another segfault (Closes: #447232)
    - Fixes segfault with with -v or -h options (Closes: #491802)
    - Fixes the region filter (Closes: #617699)
    - Fixes paths in the man page (Closes: #548591, #551344)
    - Doesn't get confused by leading blanks (Closes: #457049)
    - Inlines initialization of defaults (Closes: #317592)
    - Tests all of the IP addresses for a mirror (Closes: #320112)
   * Applied patch to copyright and other files (Closes: #645910)
   * Moved mirrors.txt from /var/cache/apt-spy to /var/cache/apt
   * Updated to latest policy, ???no changes needed?????
   * Switch to dpkg-source 3.0 (quilt) format
Checksums-Sha1: 
 22246a7707df6f7684cfc84e59e778e5e792da72 1828 apt-spy_3.2.2-1.dsc
 2c9a39a04a46c26e65151573330af46d851a2ac5 29590 apt-spy_3.2.2.orig.tar.gz
 981d6220cc67aa4be1333024e44ca1f4cfc68ec5 11593 apt-spy_3.2.2-1.debian.tar.gz
 c065fdc65e5537eae9bfac4ee83035c1ef82193a 28944 apt-spy_3.2.2-1_i386.deb
Checksums-Sha256: 
 2c609993e42b524eedd5ef8fada8aa75a189a1a6d4adc263b69059c11a86c76c 1828 
apt-spy_3.2.2-1.dsc
 f85195a71262b87a2e7f97da3e32a36c1eb0c2070985c8b40af40e980a29a3d4 29590 
apt-spy_3.2.2.orig.tar.gz
 c5d4dfef76a8f7c4326663c67d72b5e8b9d7277bcf1f4e763ee90ce62c270386 11593 
apt-spy_3.2.2-1.debian.tar.gz
 2718d79693ca9f058c957dbb257891c48ada4b761eaa840834519a75cf206a9c 28944 
apt-spy_3.2.2-1_i386.deb
Files: 
 b99ebe46dced21f805c7170591679e40 1828 admin optional apt-spy_3.2.2-1.dsc
 45964fdb457a84b8d10f7387873c0db2 29590 admin optional apt-spy_3.2.2.orig.tar.gz
 325a12b6fad979dad1a142f2bc9ecfad 11593 admin optional 
apt-spy_3.2.2-1.debian.tar.gz
 531df236fde8325b253587ac84af06a6 28944 admin optional apt-spy_3.2.2-1_i386.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQIVAwUBT1I0CocvcCxNbiWoAQI1UxAAhKqs4aKUNUQgqSTxiyntbc8y5ZFb1gL6
zS2YnRph0GSkdkttlslD3pe6zaEtJXBemqrGu7x9d2XGg90jELKOjjFPM19KkQTy
EcVR4lWN098haOInm3CXxnKEgPAc11zl+4hLf6dQf/G1KReR9LDaCSGxFNqn6hd6
uurS2jMhU6CJBkjbWk7pmvsD/11D5x3YEmHm6SHHgAVRQXxOJHFjWERVIJFYje9Z
nnm/o+/riXdNsgKp80Ae9BipoU2uKdBBgm7f0jPZ6Sey33yVWv2EZiH7+bUrwBvx
un9k8NBh83iRMcs+yJrYxoGgbF3i5TyBzsCtvusR2MIukoPrI4X3M8osHNJvVTD7
MxPJGjQk4P+DBAG/+CzFSCrFJucMzlyIcQyPMLT3zqbBGqeRtxk1oPHQukBt19wy
KdhLczFwO6NqNVa+/6cPBKfyDMmwynM/k5o16+QYNO8UESQpJENSDEwGLWhcRiOq
3+2A8yNEtzT6rIFSeDrupHgPWdZeqfhWvQqGuL2i5sy5GrxNTxJizlltcecJkb/2
6aYsuJsBv/SHJ/86hD3bgN9Gb5AEX3OrQXQOtn74og0q7h9nhaNbLZ3XCUlgqHeo
wDhTx8uGILhkHKUPUjhsaut45xl2c8yjeGWr+v/1Vl6NKjcS91TKhGKdIKe2PnKx
z5QT1R1WTZ8=
=/s/F
-----END PGP SIGNATURE-----



--- End Message ---

Reply via email to