diff mbox

[libiberty] Tweak the documentation of libiberty's xcrc32 function

Message ID 1451322488-1087-1-git-send-email-patrick@parcs.ath.cx
State New
Headers show

Commit Message

Patrick Palka Dec. 28, 2015, 5:08 p.m. UTC
In some places the xcrc32 documentation refers to GDB's own crc32
implementation, but GDB no longer has its own crc32 implementation.
It now uses libiberty's xcrc32 throughout.  So this patch removes
these references to GDB's now-nonexistent crc32 implementation.

Also, there appears to be a bug in the table-generation program embedded
within the documentation.  When the variable "int i" is >= 128, the
computation "i << 24" shifts a one bit into the sign bit (assuming a
32-bit int), which is UB.  To avoid this UB, I think it is sufficient to
make the induction variables i and j have type unsigned int.  This bug
seems latent, however.  I ran the program before and after this change
and the table output is the same.

libiberty/ChangeLog:

	* crc32.c: In the documentation, don't refer to GDB's
	now-nonexistent crc32 implementation.  In the table-generation
	program embedded within the documentation, change the type of
	the induction variables i and j from int to unsigned int, to
	avoid UB.
---
 libiberty/crc32.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Ian Lance Taylor Dec. 28, 2015, 6:44 p.m. UTC | #1
On Mon, Dec 28, 2015 at 9:08 AM, Patrick Palka <patrick@parcs.ath.cx> wrote:
>
> libiberty/ChangeLog:
>
>         * crc32.c: In the documentation, don't refer to GDB's
>         now-nonexistent crc32 implementation.  In the table-generation
>         program embedded within the documentation, change the type of
>         the induction variables i and j from int to unsigned int, to
>         avoid UB.

This is OK.

Thanks.

Ian
diff mbox

Patch

diff --git a/libiberty/crc32.c b/libiberty/crc32.c
index 12d9be0..52c982f 100644
--- a/libiberty/crc32.c
+++ b/libiberty/crc32.c
@@ -33,15 +33,14 @@ 
 
 #include "libiberty.h"
 
-/* This table was generated by the following program.  This matches
-   what gdb does.
+/* This table was generated by the following program.
 
    #include <stdio.h>
 
    int
    main ()
    {
-     int i, j;
+     unsigned int i, j;
      unsigned int c;
      int table[256];
 
@@ -146,10 +145,9 @@  starting value is @var{init}; this may be used to compute the CRC of
 data split across multiple buffers by passing the return value of each
 call as the @var{init} parameter of the next.
 
-This is intended to match the CRC used by the @command{gdb} remote
-protocol for the @samp{qCRC} command.  In order to get the same
-results as gdb for a block of data, you must pass the first CRC
-parameter as @code{0xffffffff}.
+This is used by the @command{gdb} remote protocol for the @samp{qCRC}
+command.  In order to get the same results as gdb for a block of data,
+you must pass the first CRC parameter as @code{0xffffffff}.
 
 This CRC can be specified as: