[ 
https://issues.apache.org/jira/browse/DISPATCH-1900?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17252903#comment-17252903
 ] 

ASF GitHub Bot commented on DISPATCH-1900:
------------------------------------------

jiridanek commented on a change in pull request #965:
URL: https://github.com/apache/qpid-dispatch/pull/965#discussion_r546751912



##########
File path: include/qpid/dispatch/ctools.h
##########
@@ -236,7 +236,6 @@ static inline void *qd_malloc(size_t size)
 
 static inline void *qd_calloc(size_t nmemb, size_t size)
 {
-    assert(nmemb && size);
     void *ptr = calloc(nmemb, size);
     if (!ptr) {

Review comment:
       Right. I forgot that `free(NULL)` (which is going to happen later, if 
`calloc` returned NULL) is perfectly valid. Anyways, in this case the return is 
non-zero on Ubuntu as well, so Travis is passing with this.
   
   Personally, I think that allocating zero-sized arrays and then looping over 
them is kind of neat, and I would leave that in place (and fix the check here).
   
   I fix the PR; if you want to resolve the issue differently, then feel free 
to reject the PR.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


> qd_calloc: Assertion `nmemb && size' failed.
> --------------------------------------------
>
>                 Key: DISPATCH-1900
>                 URL: https://issues.apache.org/jira/browse/DISPATCH-1900
>             Project: Qpid Dispatch
>          Issue Type: Bug
>    Affects Versions: 1.15.0
>            Reporter: Jiri Daněk
>            Priority: Major
>
> https://travis-ci.com/github/apache/qpid-dispatch/jobs/463197009#L3501
> {noformat}
> 30: Router QDR.C output file:
> 30: >>>>
> 30: 2020-12-20 11:19:09.485416 +0000 AGENT (warning) Attribute 
> 'saslConfigPath' of entity 'router' has been deprecated. Use 'saslConfigDir' 
> instead
> 30: qdrouterd: 
> /home/travis/build/apache/qpid-dispatch/include/qpid/dispatch/ctools.h:239: 
> qd_calloc: Assertion `nmemb && size' failed.
> 30: 
> {noformat}
> This is probably a mistaken assertion, because {{calloc}} is OK with zeros in 
> arguments. From the man page:
> {code}
>        The  calloc() function allocates memory for an array of nmemb elements 
> of size bytes each and re‐
>        turns a pointer to the allocated memory.  The memory is set to zero.  
> If nmemb or size is 0, then
>        calloc()  returns either NULL, or a unique pointer value that can 
> later be successfully passed to
>        free().  If the multiplication of nmemb and size would result in 
> integer overflow, then  calloc()
>        returns  an  error.  By contrast, an integer overflow would not be 
> detected in the following call
>        to malloc(), with the result that an incorrectly sized block of memory 
> would be allocated:
>            malloc(nmemb * size);
> {code}
> {code}
>     int n = qd_server->thread_count - 1; /* Start count-1 threads + use 
> current thread */
>     sys_thread_t **threads = (sys_thread_t **)qd_calloc(n, 
> sizeof(sys_thread_t*));
>     for (i = 0; i < n; i++) {
>         threads[i] = sys_thread(thread_run, qd_server);
>     }
> {code}
> Caused by https://github.com/apache/qpid-dispatch/pull/948; I missed the fact 
> it is adding these new failures under Debug build.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to