bugGNU indent - Bugs: bug #56644, `need_chars` function rounds down...

 
 

bug #56644: `need_chars` function rounds down instead of up.

Submitter:  None
Submitted:  Thu 18 Jul 2019 01:19:28 AM UTC
   
 
Category:  C Severity:  3 - Normal
Item Group:  Crash Status:  Fixed
Privacy:  Public Assigned to:  None
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 18 Apr 2021 12:24:03 PM UTC, comment #2: 
Andrej Shadura <andrewsh>
Group administrator
Thu 18 Jul 2019 01:22:48 AM UTC, comment #1: 

Sorry for the malformed link, the reference commit is as follows: c89d32a

Anonymous
Thu 18 Jul 2019 01:19:28 AM UTC, original submission:  

In commit http://git.savannah.gnu.org/cgit/indent.git/commit/src?id=c89d32a14642a80daf4d68f44cacee99c05455b6[c89d32a] when `need_chars` was moved from "handletoken.h" to "handletoken.c" the `ROUND_UP` macro was removed, but the replacement was incorrect.

This cause the program to exit with a "Virtual memory exhausted" error when it tries to reallocate 0 bytes (thus freeing the memory).  It reallocates to 0 bytes because the initial buffer size is less than 1024, and the size calculation rounds down instead of up.

Consider applying the following patch:

diff --git c/handletoken.c w/handletoken.c
index 919fba9..dfc49cc 100644
--- c/handletoken.c
+++ w/handletoken.c
@@ -85,7 +85,7 @@ extern void need_chars(buf_ty * bp, size_t needed)
 
     if (current_size + needed >= (size_t)bp->size)
     {
-        bp->size = ((current_size + needed) & (size_t)~1023);
+        bp->size = (current_size + needed + 1023) & ~(size_t)1023;
         bp->ptr = xrealloc(bp->ptr, bp->size);
         if (bp->ptr == NULL)
         {
diff --git c/parse.c w/parse.c
index a0b4401..d06a195 100644
--- c/parse.c
+++ w/parse.c
@@ -53,7 +53,7 @@ RCSTAG_CC ("$Id$");
 
 parser_state_ty *parser_state_tos = NULL;
 
-#define INITIAL_BUFFER_SIZE 1000
+#define INITIAL_BUFFER_SIZE 1024
 #define INITIAL_STACK_SIZE 2
 
 /**

Anonymous

 

(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 parakleta (Add myself (OP))
  •  

    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
        Open/ClosedOpen Closed
    2019-07-18 parakleta Carbon-Copy- Added parakleta

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code