bug-datamash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/3] improve const correctness


From: Georg Sauthoff
Subject: Re: [PATCH 3/3] improve const correctness
Date: Sun, 26 Jan 2025 22:15:43 +0100

Hello,

On Sun, Jan 26, 2025 at 08:43:23PM +0000, Tim Rice wrote:
> Thanks for the additional patches.
> 
> The first two seem fine so far, but the third one results in a compiler error:
> 
> ```
> src/utils.c: In function 'extract_number':
> src/utils.c:580:11: error: assignment discards 'const' qualifier from pointer 
> target type [-Werror=discarded-qualifiers]
>   580 |   pattern = extract_number_types[type].pattern;
>       |           ^
> ```

hm, ok, I missed that - although it's also just a warning, by default:

```
src/utils.c: In function 'extract_number':
src/utils.c:559:11: warning: assignment discards 'const' qualifier from pointer 
target type [-Wdiscarded-qualifiers]
  559 |   pattern = extract_number_types[type].pattern;
      |           ^
```

However, this should be more complete:

```
-- a/src/utils.c
+++ b/src/utils.c
@@ -538,7 +538,7 @@ guess_file_extension (const char*s, size_t len)
 
 struct EXTRACT_NUMBER_TYPE
 {
-  char *pattern;
+  const char *pattern;
   int base;
   bool floating_point;
 };
@@ -573,7 +573,7 @@ extract_number (const char* s, size_t len, enum 
extract_number_type type)
   static size_t buf_alloc;
 
   long double r = 0;
-  char *pattern;
+  const char *pattern;
   int base ;
   bool fp;

```

Best regards,
Georg

-- 
'The entered password is too long. Please enter between [ERROR]
 and [ERROR] characters.'     (Vodafone WebSessions form, 2012)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]