Mercurial > hg > octave-lyh
comparison liboctave/oct-md5.cc @ 11293:202bd0f1863d
oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 23 Nov 2010 03:11:32 -0500 |
parents | 231e6d1b57d6 |
children | 5eb10763069f |
comparison
equal
deleted
inserted
replaced
11292:231e6d1b57d6 | 11293:202bd0f1863d |
---|---|
34 #include "md5.h" | 34 #include "md5.h" |
35 | 35 |
36 static std::string | 36 static std::string |
37 oct_md5_result_to_str (const unsigned char *buf) | 37 oct_md5_result_to_str (const unsigned char *buf) |
38 { | 38 { |
39 char tmp [32]; | 39 char tmp [33]; |
40 | 40 |
41 for (octave_idx_type i = 0; i < 16; i++) | 41 sprintf (tmp, |
42 sprintf (&tmp[2*i], "%02x", buf[i]); | 42 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
43 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], | |
44 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14], | |
45 buf[15]); | |
43 | 46 |
44 return std::string (tmp, 32); | 47 return std::string (tmp, 32); |
45 } | 48 } |
46 | 49 |
47 std::string | 50 std::string |