[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #64512] Generated code uses size_t inconsistently
From: |
Keith W. Campbell |
Subject: |
[bug #64512] Generated code uses size_t inconsistently |
Date: |
Thu, 3 Aug 2023 13:50:55 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?64512>
Summary: Generated code uses size_t inconsistently
Group: gperf
Submitter: keithc61
Submitted: Thu 03 Aug 2023 05:50:53 PM UTC
Category: Generated code
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Thu 03 Aug 2023 05:50:53 PM UTC By: Keith W. Campbell <keithc61>
Two places should use size_t:
* the return type of the generated hash function should be size_t to match the
type of the parameter 'len'
* the local variable 'key' in the lookup function should have type size_t
instead of 'unsigned int'
Here is the proposed patch:
diff --git a/src/output.cc b/src/output.cc
index 63cbdac..8bc2bea 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -798,7 +798,7 @@
/* Generates C code for the hash function that returns the
proper encoding for each keyword.
The hash function has the signature
- unsigned int <hash> (const char *str, size_t len). */
+ unsigned size_t <hash> (const char *str, size_t len). */
void
Output::output_hash_function () const
@@ -829,7 +829,7 @@
if (option[KRC] | option[C] | option[ANSIC])
printf ("static ");
- printf ("unsigned int\n");
+ printf ("size_t\n");
if (option[CPLUSPLUS])
printf ("%s::", option.get_class_name ());
printf ("%s ", option.get_hash_name ());
@@ -1687,7 +1687,7 @@
{
printf (" if (len <= %sMAX_WORD_LENGTH && len >= %sMIN_WORD_LENGTH)\n"
" {\n"
- " %sunsigned int key = %s (str, len);\n\n",
+ " %ssize_t key = %s (str, len);\n\n",
option.get_constants_prefix (), option.get_constants_prefix (),
register_scs, option.get_hash_name ());
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?64512>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug #64512] Generated code uses size_t inconsistently,
Keith W. Campbell <=