Package: pgapack
Version: 1.0.0.1-3
Severity: important
Tags: patch

PGAIntegerMutation() includes a potential off-by-one error when
it selects the array index 'j' in the PGA_MUTATION_PERMUTE case.

According to the documentation PGARandomInterval(ctx, begin, end)
returns an integer in [begin, end]. As I experienced it, 'j' can
be assigned with the value ctx->ga.StringLen here. The patch below
fixes this.

--- pgapack-1.0.0.1/source/integer.c.orig       Tue Oct 11 18:36:47 2005
+++ pgapack-1.0.0.1/source/integer.c    Tue Oct 11 18:36:47 2005
@@ -470,7 +470,7 @@
                  break;
              case PGA_MUTATION_PERMUTE:
                  /* could check for j == i if we were noble */
-                 j = PGARandomInterval(ctx, 0, ctx->ga.StringLen);
+                 j = PGARandomInterval(ctx, 0, ctx->ga.StringLen - 1);
                  temp = c[i];                 
                  c[i] = c[j];
                  c[j] = temp;                 


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (1, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.11-1-686
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

-- no debconf information


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to