bugGNU indent - Bugs: bug #58515, Correctly handle pointer alignment...

 
 

bug #58515: Correctly handle pointer alignment with typedef'd types

Submitter:  Darshit Shah <darnir>
Submitted:  Sat 06 Jun 2020 10:55:16 PM UTC
   
 
Category:  C Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  andrewsh
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 18 Apr 2021 12:11:05 PM UTC, comment #2: 

I’m sorry for the extremely long reaction times — I have now applied your patch :)

Andrej Shadura <andrewsh>
Group administrator
Sat 06 Jun 2020 10:56:11 PM UTC, comment #1: 
Darshit Shah <darnir>
Sat 06 Jun 2020 10:55:16 PM UTC, original submission:  

I am copying the text from the original Mailing List post in 2019. This is not my original work, but is a bug reported last year that I am currently affected by.

This fixes a as-of-yet unreported bug, in which indent misaligns pointers
in function parameters when the parameters use a typedef type. For example,

    func f1(int *void)

renders correctly, but

    func f1(uint64_t *void)

misrenders as:

    func f1(uint64_t * void)

The problem occurs because the parser thinks `uint64_t* void` is a binary
multiplication operation, while `int *void` involves a unary dereference
operator. The pointer alignment code only adjust the spacing of unary
operators, at present.

The attached patch fixes the issue by looking for multiplications inside
function parameters and spacing them properly. With the patch, the entire
regression test suite passes on my machine, including the additional test
coverage for the bug.

P.S. Is there a better place to send this mail? I didn't see any mailing
lists besides this one, and the patches section of the Savannah project
doesn't seem to be used.

--


commit 58905ad3140b33ce6d429e3086611daccf05ec4f
Author: Nikhil Benesch <address@hidden>
Date:   Thu Apr 11 19:15:05 2019 +0200

    Correctly handle pointer alignment with typedefs

diff --git a/regression/input/pointer-pal.c b/regression/input/pointer-pal.c
index 6973a7b..eb0da73 100644
--- a/regression/input/pointer-pal.c
+++ b/regression/input/pointer-pal.c
@@ -1 +1,3 @@
 main(){int*x;x=malloc(sizeof(int));*x = 1;}
+func1(int* p) {}
+func2(uint64_t* p){uint64_t* q; p = q * q;}
diff --git a/regression/standard/pointer-pal.c
b/regression/standard/pointer-pal.c
index 1817315..7c0b5af 100644
--- a/regression/standard/pointer-pal.c
+++ b/regression/standard/pointer-pal.c
@@ -4,3 +4,13 @@ main ()
   x = malloc (sizeof (int));
   *x = 1;
 }
+
+func1 (int* p)
+{
+}
+
+func2 (uint64_t* p)
+{
+  uint64_t* q;
+  p = q * q;
+}
diff --git a/src/handletoken.c b/src/handletoken.c
index 919fba9..9880530 100644
--- a/src/handletoken.c
+++ b/src/handletoken.c
@@ -717,8 +717,10 @@ static void handle_token_binary_op(
 {
     char           * t_ptr;
            
-    if (parser_state_tos->want_blank        ||
-        (e_code > s_code && *e_code != ' '))
+    if ((parser_state_tos->want_blank || (e_code > s_code && *e_code != ' '))
+        && !(parser_state_tos->in_parameter_declaration
+             && !settings.pointer_align_right
+             && token == ''))
     {
         set_buf_break (bb_binary_op, paren_target);
         *(e_code++) = ' ';
@@ -752,7 +754,9 @@ static void handle_token_binary_op(
     }
 #endif
    
-    parser_state_tos->want_blank = true;
+    parser_state_tos->want_blank = !(parser_state_tos->in_parameter_declaration
+                                     && settings.pointer_align_right
+                                     && token == '');
 }
 
 /**

Darshit Shah <darnir>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by andrewsh (Posted a comment)
  • -email is unavailable- added by darnir (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-04-18 andrewsh StatusNone Fixed
        Assigned toNone andrewsh
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code