summaryrefslogtreecommitdiff
path: root/cpp_alloc_test/alloctest.cpp
diff options
context:
space:
mode:
authorstderr64 <stderr64@null.net>2024-10-25 00:33:24 +0300
committerstderr64 <stderr64@null.net>2024-10-25 00:33:24 +0300
commitaee8e2534d38d83c4afee8112d5030e4de8c8ad5 (patch)
treed63462855e4fb66f5ac5a24a02d51b5bb2fc9eab /cpp_alloc_test/alloctest.cpp
parentab607fc39b6dfc766f7481c33e5f1cf35a2f55d9 (diff)
downloadexperiments-aee8e2534d38d83c4afee8112d5030e4de8c8ad5.tar.gz
experiments-aee8e2534d38d83c4afee8112d5030e4de8c8ad5.tar.zst
Added local char array test
Diffstat (limited to 'cpp_alloc_test/alloctest.cpp')
-rw-r--r--cpp_alloc_test/alloctest.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/cpp_alloc_test/alloctest.cpp b/cpp_alloc_test/alloctest.cpp
index 0671901..065dcc1 100644
--- a/cpp_alloc_test/alloctest.cpp
+++ b/cpp_alloc_test/alloctest.cpp
@@ -3,11 +3,13 @@
#include <cstdint>
#include <cstring>
#include <cerrno>
+#include <unistd.h>
#include <iostream>
class AllocTest{
private: std::string *in_class_str = NULL;
private: std::string *local_str_ptr = NULL;
+ private: unsigned char *local_char_array_ptr = NULL;
public: AllocTest(){
return;
@@ -45,7 +47,12 @@ class AllocTest{
std::cout << "Local std::string no longer exists in memory\n";
return;
}
+ if ( strlen(this->local_str_ptr->c_str()) == 0 ){
+ std::cout << "Local std::string is 0 chars\n";
+ return;
+ }
std::cout << "Local std::string is still non-NULL value: " << this->local_str_ptr->c_str() << "\n";
+ this->local_str_ptr->assign( "" );
return;
}
@@ -63,6 +70,29 @@ class AllocTest{
return;
}
+ public: void test_local_char_array(){
+ unsigned char testarray[1024] = {0};
+ memset( static_cast<void*>(&testarray), 0, sizeof(testarray) );
+ memcpy( static_cast<void*>(&testarray), static_cast<const void*>("test contents"), strlen("test content") );
+ this->local_char_array_ptr = reinterpret_cast<unsigned char*>(&testarray);
+ this->is_heap_or_stack( static_cast<void*>(&testarray) );
+ return;
+ }
+
+ public: void local_char_array_exists(){
+ if ( this->local_char_array_ptr == NULL ){
+ std::cout << "Local char array pointer is NULL\n";
+ return;
+ }
+ if ( strlen(reinterpret_cast<const char*>(this->local_char_array_ptr)) == 0 ){
+ std::cout << "Local char array is 0 chars\n";
+ return;
+ }
+ std::cout << "Local char array has value: " << this->local_char_array_ptr << "\n";
+ memset( static_cast<void*>(this->local_char_array_ptr), 0, strlen((const char*)this->local_char_array_ptr) );
+ return;
+ }
+
public: ~AllocTest(){
if ( this->local_str_ptr != NULL )
this->local_str_ptr = NULL;
@@ -82,6 +112,10 @@ int main( int argc, char *args[] ){
alloc_test->test_new_std_string();
std::cout << "Testing std::string created into class\n";
alloc_test->test_in_class_str();
+ std::cout << "Testing local char array\n";
+ alloc_test->test_local_char_array();
+ std::cout << "Checking if local char array exists still\n";
+ alloc_test->local_char_array_exists();
delete alloc_test;
exit( EXIT_SUCCESS );
}