[barcode] Bugfix for Barcode_Encode

Cloyce D. Spradling cloyce@headgear.org
Wed, 7 Nov 2001 18:13:42 -0600


Hi guys.

I've not used the barcode library until today, but after reading the docs
and the code I encountered some behavior that surprised me.

In my first quick little hack, I thought that I could populate the Barcode_Item
struct myself.  That worked well enough, except that when I set
BARCODE_NO_CHECKSUM in bc->flags, I got the checksum anyway, even though
I passed 0 for the flags in Barcode_Encode.  Here's the snippet of code:

  bc = Barcode_Create("CLN014");
  bc->flags  = BARCODE_39 | BARCODE_NO_CHECKSUM | BARCODE_OUT_PS;
  bc->width  = 128; /* ~45mm */
  bc->height =  23; /* ~8mm  */
  Barcode_Encode(bc, 0);

If I call Barcode_Encode(bc, BARCODE_NO_CHECKSUM), everything is okay.  The
following patch to library.c fixes this problem for me.

--
Cloyce D. Spradling
cloyce@headgear.org

diff -ur barcode-0.97/library.c barcode-0.97.bits/library.c
--- barcode-0.97/library.c	Tue Oct 16 10:39:16 2001
+++ barcode-0.97.bits/library.c	Wed Nov  7 17:20:35 2001
@@ -133,8 +133,8 @@
     struct encoding *cptr;
 
     /* If any flag is cleared in "flags", inherit it from "bc->flags" */
-    if (!(flags & BARCODE_ENCODING_MASK))
-	flags |= bc->flags & BARCODE_ENCODING_MASK;
+    if (!(flags & validbits))
+	flags |= bc->flags & validbits;
     flags = bc->flags = (flags & validbits) | (bc->flags & ~validbits);
 
     if (!(flags & BARCODE_ENCODING_MASK)) {