Pull to refresh

Comments 2

по поводу первого варнинга:

int main(void)
{
    char buf[128];
    char *ptr = buf;
    free(ptr);
    return 0;
}
[viper@viper-manjaro ~]$ g++ main.cpp 
main.cpp: In function ‘int main()’:
main.cpp:12:13: warning: ‘void free(void*)’ called on unallocated object ‘buf’ [-Wfree-nonheap-object]
   12 |         free(ptr);
      |         ~~~~^~~~~
main.cpp:8:10: note: declared here
    8 |     char buf[128];
      |  

gcc и так понял, что происходит косвенное освобождение non-heap памяти. про явное и подавно ругнется.

V726 An attempt to free memory containing the 'wbuf' array by using the 'free' function. This is incorrect as 'wbuf' was created on stack. log.cpp 216

хз почему, но читается очень тяжело. зачем писать - this is incorrect в ошибках? бывают корректные ошибки? "free() called on stack allocated object (wbuf)".

Sign up to leave a comment.

Information

Website
pvs-studio.ru
Registered
Founded
2008
Employees
51–100 employees
Location
Россия
Representative
Андрей Карпов