Gladiator
👍
14•08
#include <stdio.h> #include <stdlib.h> /* required for the malloc and free functions */ int main() { int number; int *ptr; int i; printf("How many ints would you like store? "); scanf("%d", &number); ptr =malloc(number*sizeof(int)); /* allocate memory */ if(ptr!=NULL) { for(i=0 ; i<number ; i++) { *(ptr+i) = i; } for(i=number ; i>0 ; i--) { printf("%d\n", *(ptr+(i-1))); /* print out in reverse order */ } free(ptr); /* free allocated memory */ return 0; } else { printf("\nMemory allocation failed - not enough memory.\n"); return 1; } }
14•08
Ishud copy in pastebin
Anonymous
No
you got two groups of people , people that C guys and C++ guys that hate on C and say that C style of coding is not good . OOP lovers , and there are some who are not so bias
14•08
Ok
14•08
https://pastebin.com/SEd6AuRy
András
MVC++ is the first compiler that supports C++17 fully
Yet, I easy can write code, that c++latest wont compile, but c++17 will
14•08
What about g++?
It's gud
David🇨🇺ElChino
It's gud
That's the one I use
klimi
I thought clang has c++17 support too
Francisco
Francisco
It's libc++ what's not fully completed
klimi
Hm
Francisco
Hm
https://en.cppreference.com/w/cpp/compiler_support
Anonymous
It supports full C++17
i jsut dont like apple tryna force you to use Clang
Anonymous
after an update, they made it a pain in the ass to install GNU
Francisco
Well, clang is a really good compiler after all
David🇨🇺ElChino
So Open Source compilers won't fully support c++17? I don't think so
Francisco
I use both gcc and clang
Anonymous
professor
if a memory leak becomes a dangling pointer after delete how can I fix this ?
Anonymous
After you delete a pointer p pointing to some allocated memory, just don't use the value in the pointer anymore: either don't use the variable at all or overwrite it with something else.
professor
int* ptr = new int(5); memory leak delete ptr # fix memory leak if we dont add ptr = NULL we got information leak right? # info leak fix return ptr
professor
is this what you mean?
Anonymous
^It's not a memory leak
Anonymous
A memory leak would be:
Anonymous
int *ptr = new int[5]; //Do stuff ptr = nullptr; //We lose the originally allocated 5 ints, and there's no way to delete them; We 'leak' memory
Anonymous
I'm showing him what a memory leak is: to show what it is you wouldn't use unique_pointers
professor
in a few words after delete , free becomes a dang pointer and a new vuln information leak , and we need to point to null to fix right ?
Raz
in a few words after delete , free becomes a dang pointer and a new vuln information leak , and we need to point to null to fix right ?
No You should use smart pointers or some container instead (assuming you use C++ and not C)
professor
If i do this then it will keep the info leak bug
Raz
If i do this then it will keep the info leak bug
Well, no Read about unique_pointer or vector
professor
I will check and smart pointers too
Anonymous
unique_pointer is a smart pointer; there's a couple more
Raz
I will check and smart pointers too
Just to note: using raw pointers as well as new and delete, is a bad practice
Anonymous
except if you're stuck with pre-C++11 C++ for some reason
David🇨🇺ElChino
professor
So this isn't the right way to delete a pointer?
Nope those contains vulnerabilities
professor
I am just checking appsec c++ that’s why delete , new , free
Anonymous
free is a C function from stdlib.h
David🇨🇺ElChino
Raz
So this isn't the right way to delete a pointer?
Yes, if you write C++98 or C++03 Then, yes its fine Just assign your deleted pointer to NULL, for preventing UB
professor
What is the right way?
If you dont delete or resign memory leak and info leak will be
professor
Some mate says smart pointers and other thing
Anonymous
You don't delete memory leaks, since a memory leak is when you have memory to which you have no pointer anymore; You 'delete' allocated (with new) memory.
Anonymous
No, i mean the delete keyword.
Raz
Some mate says smart pointers and other thing
If you want to protect against info leaks Just assign your raw pointer to nullptr/NULL after deleting it. Also, assign your new allocated memory, if it has not been assigned yet.
Anonymous
Both are used for same purpose, but still they have some differences, the differences are: delete is an operator whereas free() is a library function. delete free the allocated memory and calls destructor. But free() de-allocate memory but does not call destructor.
Anonymous
from google , i see they are similar
Anonymous
i learning how to deal with memory leaks now
14•08
#cpp
14•08
/notes
Bennie
/get gcc9
Bennie
/get stop-teaching-c
Bennie
😏 no notes on digraph and trigraph sequences - https://www.google.com/amp/s/developerinsider.co/what-is-digraphs-trigraphs-and-tokens-c-cpp-programming-language/amp/
Daniyar
Hi, which course you recommend on "coursera" to learn c++?
Tokin
Who here has experience with WinAPI?
bandhan
i need to limit android app data limit like by editing the apk pls help
bandhan
like 100 kb/s speed
Anonymous
Anonymous
I want the insertion point to be up and not down every time I press ENTER
Anonymous
I am using the Codeblocks IDE