Note that there are some explanatory texts on larger screens.

plurals
  1. POconst unsigned char* conversion to/from string or const char*
    primarykey
    data
    text
    <p>I am lost in the underworld of pointers! Here is my problem,</p> <p>It is very quirky and I can only control one of the functions so please don't say I need to redesign. This is being compiled in Linux Ubuntu 11.04 using android-ndkr7. It is a purely native application (or service) that will run on an android phone. I am using google test to verify my class/functions. The first function (my test class) has to declare the unsigned char*, it passes it to the 2nd function to be used as output (crypt::encryptBuffer), encrypt takes the declared variable, allocates memory for it and passes it to a third function which is where the value is being placed into it as output. </p> <p>Crypt.h</p> <pre><code>class Crypt { public: Crypt(); ~Crypt(); bool encryptBuffer(const unsigned char* inDecryptBuffer, const int inputSize, unsigned char** outEncryptBuffer, int* pOutSize); }; #endif </code></pre> <p>Crypt.cpp</p> <pre><code>#include "Crypt.h" #include "pan/crypt.h" static unsigned char HydraEncryptionKey[] = {0x17, 0x43, 0x9B, 0x55, 0x07, 0xAE, 0x73, 0xB1, 0x32, 0x10, 0xE0, 0x22, 0xD9, 0xC7, 0xF2, 0x3B}; bool AccCrypt::encryptBuffer(const unsigned char* inDecryptBuffer, const int inputSize, unsigned char** outEncryptBuffer, int* pOutSize) { int encryptedSize; pan::aes128_cbc enc(HydraEncryptionKey); // see how long the encrypted data will be and allocate space for the data encryptedSize = enc.output_len( inputSize ); *outEncryptBuffer = (unsigned char*)malloc(encryptedSize + 4); enc.encrypt(inDecryptBuffer, *outEncryptBuffer, inputSize ); return true; } </code></pre> <p>CryptTest.cpp</p> <pre><code>#incude "Crypt.h" #include &lt;gtest/gtest.h&gt; #define CHECK_COND(X, a, b, c) { \ if(X) \ { \ printf("FAIL: %s\n", c); \ printf("Press any key to continue");\ getc(stdin);\ }\ else \ { \ printf("PASS: %s\n", c); \ }\ } #define EXPECT_EQ(a,b,c) CHECK_COND((a != b), a, b, c) const char* decBuff = "something"; const int inputSize = 10; unsigned char* encBuffTest = NULL; int pOutsize = 0; class cryptTester : public testing::Test { protected: virtual void SetUp() { cryptTest = new Crypt(); cryptTest-&gt;encryptBuffer((const unsigned char*)decBuff, inputSize, &amp;encBuffTest, &amp;pOutsize); } virtual void TearDown() { } Crypt* cryptTest; }; TEST_F(AccCryptTest, decryptBuffer) { int poutSize = 0; EXPECT_EQ(true, accCryptTest-&gt;decryptBuffer((const unsigned char*)encBuffTest, pOutsize, &amp;outDecryptBuffTest, &amp;poutSize), "decryptBuffer(valid, valid)"); } </code></pre> <p>This will compile fine, however when I run it on the phone I get a segmentation fault. I cannot figure out where this is happening as I have not been able to setup debugging correctly from the adb shell. </p> <p>Any help would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload