Anonymous
And the vulnerability is?
You should try putting it into the code
Anonymous
See what happens
V01D
Lemme guess, you get a negative number
V01D
Or buffer overflow
V01D
probably buffer overflow
Anonymous
It is undefined what happens
V01D
Don't values wrap around to its lowest value
Mar!o
Just make it an unsigned an it's no longer undefined behaviour.
Pavel
Don't values wrap around to its lowest value
Signed overflow considered UB by C++ standard
V01D
So it was right?
Pavel
UB?
Undefined behavior
V01D
Oh. I thought it wasn't. Guess I got signed and unsigned mixed up
V01D
What if a signed int is needed? Isn't this a fundamental flaw?
Anonymous
Reverse the string
Anonymous
Then compare both strings
Mar!o
It is indeed a misdesign in the C/C++ standart in my opinion! The compiler can use UB to optimize, but I don't care. I mean we have C++20 and signed overflow is still UB - that's one of the reasons I use Rust...
Harsh
Then compare both strings
You can do: scan str rev_str = strrev(str) if(strcmpi(str, rev_str)==0) > palindrome Else >Not
Mar!o
When I use Assembly I'm very carefully but if I write in a high-level language I want to be save from that shit... Don't get my wrong I love C and C++ but some designs are just stupid in my opinion...
Mar!o
So there is nothing I can do about it?
You could do some overflow checks. There are ways to fix/prevent it... you can search them up on Stackoverflow probably.
Harsh
You can do: scan str rev_str = strrev(str) if(strcmpi(str, rev_str)==0) > palindrome Else >Not
Also if you still want to loop I'd recommend comparing left end and right end till mid . That's what i was taught in schools atleast
Cristian
Anyone knows how to do this with c graphics?
V01D
Is there a book or a video that teaches how to writer SAFE code?
V01D
Anyone knows how to do this with c graphics?
learnopengl.com is a starting point
Harsh
Is there a book or a video that teaches how to writer SAFE code?
It's like driving a car. You can see cautions and warning etc but real thing is experience
Mar!o
Probably, I don't have any but I think there is a book called "Safer C" or something like that. My original idea was to build my language and VM in C but there are just better options like Rust. Today I use Rust and Assembly in combination with some C sometimes. Rust might not have a real ISO standard yet, but without the "unsafe" keyword there is almost no way to invoke UB.
Mar!o
Imagine having a car or plane crash because of UB in a VM!
V01D
Well , I am a game dev. Unreal engine, I have to use C++, so...
Mar!o
No thanks 😅
That's why there are special versions of C for cars or rockets but C is old and sometimes we should move on to newer tools.
Mar!o
Well , I am a game dev. Unreal engine, I have to use C++, so...
Modern C++ is at least far better than C, even tough "Unreal C++" is not so modern.
Konstantin
Is there a book or a video that teaches how to writer SAFE code?
Writing Secure Code by Michael Howard and David LeBlanc
Mar!o
Embedded C?
MISRA C for example
Mar!o
These are basically strict guidelines.
Mohit ^_^
Let's say I have 2 vectors of char, say a and b, and I want to link one to another. I created an array of pointers, but after I use std::sort on 'a', the pointer address is changed to sorted order of a. I still want to keep the old reference somehow but can't figure out how. Any suggestions ?
Mohit ^_^
Thanks. Actually I want to bind a to b such that I can go from b to a directly, without traversing and searching the entire sorted list, a. a & b are identical initially but I've sorted a later.
Mohit ^_^
Got it. Tysm Madhu
Vlad
From allocating singular ints on the heap, to using new and delete in the first place
Dima
I use Arch, btw
Dima
King Phyte 🐍
I use Arch, btw
Arch Linux?
Anonymous
I use Arch, btw
/warn offtop
Anonymous
/warn offtop
Vlad
2d array is an array of arrays
Vlad
Think of it as it's a T**
Vlad
You derefence it twice
Vlad
By the first and second subscript accordingly
Vlad
Yes
Vlad
But we move inside the row
Vlad
Nvm you move along the row
Vlad
Not the column
Vlad
It is
Vlad
cuz second subscript selects a column
Vlad
int arr[height][width]; for(int i = 0; i < height; ++i) { for(int j = 0; j < width; ++j) { printf("%d ", arr[i][j]); } printf("\n"); } Stare at this piece of code until you get it
INDIA
What help you want exactly?
#include<iostream> using namespace std; class Employee; class clerk { public: void print(Employee); }; class Employee { string name,gender,dep; int empid,age,sal; public: friend void clerk::print(Employee); void read() { cout<<"\n enter name "; cin>>name; cout<<"\n enter empid "; cin>> empid; cout<<"\n enter age"; cin>>age; cout<<"\n enter gender "; cin>>gender; cout<<"\n enter salary "; cin>>sal; cout<<"\n enter department"; cin>>dep; } void show() { cout<<"\n the information of employee is:"; cout<<"\n name "<<name; cout<<"\n empid "<<empid; cout<<"\n age"<<age; cout<<"\n gender"<<gender; cout<<"\n salary"<<sal; cout<<"\n department"<<dep; } Employee() { cout<< "\n default constructer called"; } ~Employee() { cout<<"\n destructor called"; } }; void clerk::print(Employee emp) { cout<<"\n name "<<emp.name; cout<<"\n age "<<emp.age; cout<<"\n gender "<<emp.gender; cout<<"\n salary "<<emp.sal; cout<<"\n department "<<emp.dep; } int main() { Employee emp; emp.read(); clerk cl; cl.print(emp); }
INDIA
What help you want exactly?
#include<iostream> using namespace std; class Employee; class clerk { public: void print(Employee); }; class Employee { string name,gender,dep; int empid,age,sal; public: friend void clerk::print(Employee); void read() { cout<<"\n enter name "; cin>>name; cout<<"\n enter empid "; cin>> empid; cout<<"\n enter age"; cin>>age; cout<<"\n enter gender "; cin>>gender; cout<<"\n enter salary "; cin>>sal; cout<<"\n enter department"; cin>>dep; } void show() { cout<<"\n the information of employee is:"; cout<<"\n name "<<name; cout<<"\n empid "<<empid; cout<<"\n age"<<age; cout<<"\n gender"<<gender; cout<<"\n salary"<<sal; cout<<"\n department"<<dep; } Employee() { cout<< "\n default constructer called"; } ~Employee() { cout<<"\n destructor called"; } }; void clerk::print(Employee emp) { cout<<"\n name "<<emp.name; cout<<"\n age "<<emp.age; cout<<"\n gender "<<emp.gender; cout<<"\n salary "<<emp.sal; cout<<"\n department "<<emp.dep; } int main() { Employee emp; emp.read(); clerk cl; cl.print(emp); }
Harsh
Huh;_;
INDIA
Sir I am not able to understand how friend function can take empid and display all other information
INDIA
Huh;_;
Sir how this question can be done using arrays
INDIA
Huh;_;
Thanku sir for responding to my message🙏🙏
Harsh
Sir I am not able to understand how friend function can take empid and display all other information
https://www.tutorialspoint.com/cplusplus/cpp_friend_functions.htm#:~:text=A%20friend%20function%20of%20a,friends%20are%20not%20member%20functions.
Anonymous
Write a program in c++ that fined the area of a cub
Anonymous
Please any one help me ow
Talula
Write a program in c++ that fined the area of a cub
Please learn to program or leave the programming course.
Valentine
Hi! Why does this thing behaves like this?
Valentine