Skip to content

Commit

Permalink
avoid conversion from string constant to 'char*'
Browse files Browse the repository at this point in the history
Warning was (gcc):

.../examples/LibusbTest.cpp: In function ‘int main(int, char**)’:
.../examples/LibusbTest.cpp:481:82: warning:
    deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    std::shared_ptr<unsigned char> pPingString = allocString("PING!", pingDataSize);
                                                                                  ^
.../examples/LibusbTest.cpp:625:84: warning:
    deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    std::shared_ptr<unsigned char> pPingString = allocString("apostle", pingDataSize);
                                                                                    ^
.../examples/LibusbTest.cpp:768:84: warning:
    deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
    std::shared_ptr<unsigned char> pPingString = allocString("apostle", pingDataSize);
                                                                                    ^

Warning was (clang):

.../examples/LibusbTest.cpp:481:61: warning: ISO
      C++11 does not allow conversion from string literal to 'char *'
      [-Wwritable-strings]
  ...std::shared_ptr<unsigned char> pPingString = allocString("PING!", pingDa...
                                                              ^
.../examples/LibusbTest.cpp:625:61: warning: ISO
      C++11 does not allow conversion from string literal to 'char *'
      [-Wwritable-strings]
  ...std::shared_ptr<unsigned char> pPingString = allocString("apostle", ping...
                                                              ^
.../examples/LibusbTest.cpp:768:61: warning: ISO
      C++11 does not allow conversion from string literal to 'char *'
      [-Wwritable-strings]
  ...std::shared_ptr<unsigned char> pPingString = allocString("apostle", ping...
                                                              ^

Related-to-issue: zarthcode#2
Signed-off-by: Stephan Linz <[email protected]>
  • Loading branch information
rexut committed Nov 28, 2016
1 parent 12bed31 commit e7bc850
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/LibusbTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
// Utility functions

/// Creates a std::shared_ptr<unsigned char> containing a wide string. (demo)
std::shared_ptr<unsigned char> allocWString(wchar_t* pString, size_t& outSize);
std::shared_ptr<unsigned char> allocWString(const wchar_t* pString, size_t& outSize);

/// Creates a std::shared_ptr<unsigned char> containing a string. (demo)
std::shared_ptr<unsigned char> allocString(char* pString, size_t& outSize);
std::shared_ptr<unsigned char> allocString(const char* pString, size_t& outSize);


// Test results
Expand Down Expand Up @@ -914,7 +914,7 @@ int main(int argc, char* argv[])
return failBit ? EXIT_FAILURE : EXIT_SUCCESS;
}

std::shared_ptr<unsigned char> allocWString( wchar_t* pString, size_t& outSize )
std::shared_ptr<unsigned char> allocWString( const wchar_t* pString, size_t& outSize )
{

size_t strSize = wcslen(pString);
Expand All @@ -929,7 +929,7 @@ std::shared_ptr<unsigned char> allocWString( wchar_t* pString, size_t& outSize )

}

std::shared_ptr<unsigned char> allocString( char* pString, size_t& outSize )
std::shared_ptr<unsigned char> allocString( const char* pString, size_t& outSize )
{

size_t strSize = strlen(pString);
Expand Down

0 comments on commit e7bc850

Please sign in to comment.