screen-devel
[Top][All Lists]
Advanced

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

[screen-devel] [bug #66417] incorrect calloc use?


From: Jeffrey Cliff
Subject: [screen-devel] [bug #66417] incorrect calloc use?
Date: Wed, 6 Nov 2024 14:08:52 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?66417>

                 Summary: incorrect calloc use?
                   Group: GNU Screen
               Submitter: themusicgod1
               Submitted: Wed 06 Nov 2024 01:08:49 PM CST
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 5.0.0
           Fixed Release: None
         Planned Release: None
           Work Required: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Wed 06 Nov 2024 01:08:49 PM CST By: Jeffrey Cliff <themusicgod1>
gcc (GCC) 15.0.0 20240509 (experimental)
screen: 5.0

from man calloc: 

       void *calloc(size_t nmemb, size_t size);

       The  calloc() function allocates memory for an array of *nmemb*
elements of *size* bytes each and returns a pointer to the allocated memory.
The memory is set to zero. ...

ie what we're doing is multiplyinig size*nmemb instead of size*nmemb which
*should* be equal but it is still backwards.
 
this is now a warning
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112364

# diff -Naur screen-5.0.0/list_license.c  screen-compiles/list_license.c 
--- screen-5.0.0/list_license.c 2024-08-28 13:55:03.000000000 -0600
+++ screen-compiles/list_license.c      2024-11-06 13:04:11.149682631 -0600
@@ -96,7 +96,7 @@
 {
        (void)ldata; /* unused */
 
-       char *line = calloc(sizeof(char), flayer->l_width + 1);
+       char *line = calloc(flayer->l_width + 1,sizeof(char));
        char *start = (char *)lrow->data;
        char *lastspace = start;
        size_t linelen = 0;

merely changing the order of arguments to put the size at the end (ie
sizeof(char)) is what gcc seems to be looking for. it *shouldn't* affect
anything other than this gcc warning, but it's good practice to use the API
properly rather than backwards as well.







    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?66417>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature


reply via email to

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