Coverity doesn't complain even with testing to -1, so better patch included.

Regards,
  Honza

Jan Friesse wrote:
> Steven Dake wrote:
>> On 06/01/2011 09:14 AM, Jan Friesse wrote:
>>> Signed-off-by: Jan Friesse <jfrie...@redhat.com>

>....

>> Prefer a direct comparison for the error condition ie:
>> if (page_size == -1) {
>> }
>> RETURN VALUE
>>        If name is invalid, -1 is returned, and errno is set to EINVAL.
>> Other‐
>>        wise, the value returned is the value of the system resource and
>>  errno
>>        is  not  changed.  In the case of options, a positive value is
>> returned
>>        if a queried option is available, and -1 if it is not.  In the
>> case  of
>>        limits, -1 means that there is no definite limit.
>>
>>
> 
> Main problem is not -1 but fact, that malloc takes unsigned and sysconf
> return signed. According to man page:
> 
>  PAGESIZE - _SC_PAGESIZE
>               Size of a page in bytes. Must not be less than 1.  (Some
> systems use PAGE_SIZE instead.)
> 
> So I can imagine test for < 1, but patch seem to me makes much more
> sense with < 0.
> _______________________________________________
> Openais mailing list
> Openais@lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/openais

From b2992625ca8667b75ca0221ddd34cf7e88c2802e Mon Sep 17 00:00:00 2001
From: Jan Friesse <jfrie...@redhat.com>
Date: Mon, 30 May 2011 13:15:02 +0200
Subject: [PATCH] coroipcc: Test _SC_PAGESIZE result

Signed-off-by: Jan Friesse <jfrie...@redhat.com>
---
 lib/coroipcc.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/coroipcc.c b/lib/coroipcc.c
index c5196a6..dff7616 100644
--- a/lib/coroipcc.c
+++ b/lib/coroipcc.c
@@ -311,6 +311,10 @@ circular_memory_map (char *path, const char *file, void 
**buf, size_t bytes)
        }
 
        page_size = sysconf(_SC_PAGESIZE);
+       if (page_size == -1) {
+               goto error_close_unlink;
+       }
+
        buffer = malloc (page_size);
        if (buffer == NULL) {
                goto error_close_unlink;
@@ -417,6 +421,10 @@ memory_map (char *path, const char *file, void **buf, 
size_t bytes)
                goto error_close_unlink;
        }
        page_size = sysconf(_SC_PAGESIZE);
+       if (page_size == -1) {
+               goto error_close_unlink;
+       }
+
        buffer = malloc (page_size);
        if (buffer == NULL) {
                goto error_close_unlink;
-- 
1.7.1

_______________________________________________
Openais mailing list
Openais@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to