Skip to content

Commit

Permalink
Fix warning about sprintf usage (KeyviDev#286)
Browse files Browse the repository at this point in the history
remove methods in question that produce the warning instead of fixing, because it is not used anyway.
  • Loading branch information
hendrikmuhs authored Feb 19, 2024
1 parent 8672308 commit edf518f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
26 changes: 1 addition & 25 deletions keyvi/3rdparty/misc/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// The original md5 implementation avoids external libraries.
// This version has dependency on stdio.h for file input and
// string.h for memcpy.
#include <stdint.h>
#include <stdio.h>
#include <string.h>

Expand Down Expand Up @@ -317,36 +318,11 @@ class MD5
memset((POINTER)&context, 0, sizeof (context));
}

/// Buffer must be 32+1 (nul) = 33 chars long at least
void writeToString()
{
int pos ;

for( pos = 0 ; pos < 16 ; pos++ )
sprintf( digestChars+(pos*2), "%02x", digestRaw[pos] ) ;
}


public:
// an MD5 digest is a 16-byte number (32 hex digits)
BYTE digestRaw[ 16 ] ;

// This version of the digest is actually
// a "printf'd" version of the digest.
char digestChars[ 33 ] ;

// Digests a string and prints the result.
char* digestString( const char *string )
{
Init() ;
Update( (unsigned char*)string, strlen(string) ) ;
Final() ;

writeToString() ;

return digestChars ;
}

uint64_t Hash( const char * string )
{
Init();
Expand Down
12 changes: 3 additions & 9 deletions keyvi/tests/keyvi/dictionary/util/md5_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,28 @@
* Author: hendrik
*/

#include "md5.h"

#include <boost/test/unit_test.hpp>

#include "md5.h"

namespace keyvi {
namespace dictionary {
namespace util {

BOOST_AUTO_TEST_SUITE( MD5Tests )
BOOST_AUTO_TEST_SUITE(MD5Tests)

BOOST_AUTO_TEST_CASE( MD5HashTest ) {
BOOST_AUTO_TEST_CASE(MD5HashTest) {
misc::MD5 m = misc::MD5();

BOOST_CHECK_EQUAL(m.digestString("test"), "098f6bcd4621d373cade4e832627b4f6");

BOOST_CHECK_EQUAL(14618207765679027446U, m.Hash("test"));
BOOST_CHECK_EQUAL(13339385412431753948U, m.Hash("MYKEY"));
BOOST_CHECK_EQUAL(16825458760271544958U, m.Hash(""));
BOOST_CHECK_EQUAL(17513079290081602220U, m.Hash("LLLLLLLLLLLOOOOOOOOOOOONNNNNNNNNNNGGGGGGGGGG"));
BOOST_CHECK_EQUAL(13356017483753479679U, m.Hash("-------------------------------------"));
}


BOOST_AUTO_TEST_SUITE_END()

} /* namespace util */
} /* namespace dictionary */
} /* namespace keyvi */


0 comments on commit edf518f

Please sign in to comment.