I am using strcpy on two char arrays with destination array smaller than the source array. But strcpy doesn't seem to care. In fact, it copies source array shamelessly to the destination array and I can even cout the new destination array.
#include <iostream>
#include <cstring>
int main(){
char src_str[10] = {'D','e','s'};
char dst_str[2] = {'S', 'r'};
strcpy(dst_str, src_str);
std::cout << dst_str << std::endl;
std::string stdstr(dst_str);
std::cout << "stdstr: " << stdstr << std::endl;
std::cin.ignore();
}
It prints;
Des
stdstr: Des
I am compiling with g++ (5.4.0) on Ubuntu.