Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
59 user(s) are online (42 user(s) are browsing Forums)

Members: 1
Guests: 58

328gts, more...

Support us!

Headlines

Report message:*
 

Re: Porting to AmigaOS4 thread

Subject: Re: Porting to AmigaOS4 thread
by kas1e on 2021/1/13 15:32:39

@sTix
Quote:

With gcc 10 you can also use the -fanalyzer option to find even more bugs


Wow, tried simple test case with wrong-double-free:

#include<stdio.h>
#include <stdlib.h>

int main()
{
        
int *ptr_one;

        
ptr_one = (int *)malloc(sizeof(int));

        if (
ptr_one == 0)
        {
                
printf("ERROR: Out of memoryn");
                return 
1;
        }

        *
ptr_one 25;
        
printf("%dn", *ptr_one);

        
free(ptr_one);
        
free(ptr_one);

        return 
0;
}


And -fanalyzer works, see:

user@DESKTOP-3NFAB0O /amiga
ppc-amigaos-gcc -fanalyzer 1.c -o 1
1.c
In function ‘main’:
1.c:20:9warningdouble-‘free’ of ‘ptr_one’ [CWE-415] [-Wanalyzer-double-free]
   
20 |         free(ptr_one);
      |         ^~~~~~~~~~~~~
  
‘main’events 1-6
    
|
    |    
|         ptr_one = (int *)malloc(sizeof(int));
    |      |                          ^~~~~~~~~~~~~~~~~~~
    |      |                          |
    |      |                          (
1allocated here
    
|    |
    |   
10 |         if (ptr_one == 0)
    |      |            ~
    |      |            |
    |      |            (
2assuming ‘ptr_one’ is non-NULL
    
|      |            (3following ‘false’ branch (when ‘ptr_one’ is non-NULL)...
    |......
    |   
16 |         *ptr_one 25;
    |      |         ~~~~~~~~~~~~~
    |      |                  |
    |      |                  (
4) ...to here
    
|      |                  (5first ‘free’ here
    
|......
    |   
20 |         free(ptr_one);
    |      |         ~~~~~~~~~~~~~
    |      |         |
    |      |         (
6second ‘free’ herefirst ‘free’ was at (5)
    |

user@DESKTOP-3NFAB0O /amiga


Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project