detergentTikiya
I am getting Heap-buffer-overflow at some point in this small code, I fail to understand why. Till line#18, I could print the returnSize array content very well..then how is this a heap-overflow?
Anonymous
Hello
Anonymous
Hello
detergentTikiya
if a and b are pointing to the same address and it's not lost, why can't I access the array from inside main?
detergentTikiya
You change b and return it, but dont save return in main
I didn't get save return in main part
Artöm
a = foo(a)
detergentTikiya
Yes, I do change b, but the address which b is pointing to is what a is also pointing to.
Artöm
When you change b, a remains unchanged
detergentTikiya
a = foo(a)
I deliberately didn't do that. Reason: malloc does allocation in a heap segment. That segment is available until we free or terminate the program. Now b is pointing to contiguous blocks of 4 ints. So, if I know address contained in b, I should be able to know about values also that are contained in those 4 blocks, shouldn't I?
Anonymous
I am seeing openssl/md5.h and hex.h for.the very first time.
Might be that are the header files created by him Because our own created header files are not written like the standerd header file are writeen So it is written like #include"anything.h"
Anonymous
So that hex.h are header file created by him for any of his specific need
Siddharth Sahoo
I was also thinking about it and what about openssl/md5 ? That is also written by him ?
detergentTikiya
What is line 7 intend to do here ?
Reserving 4 contiguous blocks of size 4 bytes in heap
Siddharth Sahoo
detergentTikiya
Why before malloc, there is (*int)?
Not really needed, but having or not having it is not problem
Siddharth Sahoo
Not really needed, but having or not having it is not problem
But then in that particular code why he/she used it ?
detergentTikiya
But then in that particular code why he/she used it ?
I can remove it. But that won't make a difference. I do it for my understanding only
Nyuke
can someone help me with this code?
Nyuke
https://pastebin.com/20kAGStk
Nyuke
getting an error like this : warning: no return statement in function returning non-void [-Wreturn-type] }
Anonymous
getting an error like this : warning: no return statement in function returning non-void [-Wreturn-type] }
Because the compiler doesn't think the func at line 11 is constructor
Nyuke
then what should i do about that?
Anonymous
then what should i do about that?
Have you ever think about why compiler doesn't treat it as constructor?
Anonymous
Its name doesn't match up with the class name bro
Nyuke
AH!
Nyuke
got it
Nyuke
sorry man, thanks tho
Anonymous
Anonymous
#include<iostream> using namespace std; int N = 10; int main() { static int x = 1; if (cout << x << " " && x++ < N && main()) { } return 0; }
Anonymous
What does && in the above program does?
Lao
Hi guys
Anonymous
/Hi
Anonymous
✋hi!!
detergentTikiya
What does && in the above program does?
is a logical binary operator and takes two operands
Ben
What does && in the above program does?
As far as i understood you can replace main() with 0
Ben
that can not be replaced
This kind of shitty code i seen the first time 😂
detergentTikiya
Did a gdb there, can clearly see a and b hold same addresses
Lao
me too, but it's a little bit interesting ,becuese there is a Recursion, it should ended till the x reach the N
Lao
i'm sure it does.
Ben
i'm sure it does.
Oh god , why do people need to write this kind of shit 😂😂
Lao
this can help u to understand the && operator's priority
detergentTikiya
Did they even after foo is closed?
Not sure about b because once foo exited, we can't access b. But a still hold the same address
Lao
detergentTikiya
My code doesn't use reference. It's a C program
detergentTikiya
Then return int* or pass int**
Why? Without doing that why consecutive blocks of memory are not accessible outside of foo (via a)?
Mat
b doesn't exists anymore after foo is closed
Lao
the B pointer in foo , got NULL, not a 's address
Artöm
detergentTikiya
Cause b is a copy of a. When you change b, a holds old value
Doesn't a have the same address as b despite b doesn't exist anymore?
Artöm
Thing is, if oarameter is a pointer, it isn't always pass-by-reference
detergentTikiya
Imagine a, b are int. b is copy of a. Here you have same situation
They are at two different memory addresses. In my case, it's the same memory addres that a and b are pointing to
detergentTikiya
Only before call. When b is changed, they point to different addresses
How has b changed? It still points to the start of the memory block ..right?
Artöm
a didn't
detergentTikiya
b = ... b changed
Which line number has b changed in?
detergentTikiya
The malloc one
But I did a gdb..and just before foo exits, b holds the same address which it held at the beginning of foo
detergentTikiya
Points to or has?
I did print b
Mat
And after?
detergentTikiya
So it has or points to are same