annotate liboctave/util/oct-md5.cc @ 20827:e54ecb33727e

lo-array-gripes.cc: Remove FIXME's related to buffer size. * lo-array-gripes.cc: Remove FIXME's related to buffer size. Shorten sprintf buffers from 100 to 64 characters (still well more than 19 required). Use 'const' decorator on constant value for clarity. Remove extra space between variable and array bracket.
author Rik <rik@octave.org>
date Mon, 12 Oct 2015 21:13:47 -0700
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
1 /*
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
2
19898
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
3 Copyright (C) 2007-2015 David Bateman
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
4
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
5 This file is part of Octave.
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
6
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
10 option) any later version.
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
11
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
15 for more details.
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
16
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6383
diff changeset
19 <http://www.gnu.org/licenses/>.
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
20
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
21 */
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
22
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
15268
307912900544 Use angle brackets for #include <config.h> for consistency.
Rik <rik@octave.org>
parents: 15018
diff changeset
24 #include <config.h>
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
25 #endif
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
26
8521
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
27 #include <cstdio>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
28
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
29 #include <string>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
30 #include <vector>
93cf10950334 tmpdir=tmpnam;
Rafael Laboissiere <rafael@debian.org>
parents: 8377
diff changeset
31
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
32 #include "lo-error.h"
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
33 #include "oct-md5.h"
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
34 #include "md5.h"
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
35
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
36 static std::string
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
37 oct_md5_result_to_str (const unsigned char *buf)
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
38 {
15018
3d8ace26c5b4 maint: Use Octave coding conventions for cuddled parentheses in liboctave/.
Rik <rik@octave.org>
parents: 14846
diff changeset
39 char tmp[33];
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
40
11293
202bd0f1863d oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents: 11292
diff changeset
41 sprintf (tmp,
202bd0f1863d oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents: 11292
diff changeset
42 "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
202bd0f1863d oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents: 11292
diff changeset
43 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7],
202bd0f1863d oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents: 11292
diff changeset
44 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13], buf[14],
202bd0f1863d oct_md5_result_to_str: avoid buffer overrun; replace loop with single call to sprintf
John W. Eaton <jwe@octave.org>
parents: 11292
diff changeset
45 buf[15]);
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
46
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
47 return std::string (tmp, 32);
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
48 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
49
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
50 std::string
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
51 oct_md5 (const std::string str)
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
52 {
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
53 unsigned char buf[16];
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
54
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
55 md5_buffer (str.data (), str.length (), buf);
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
56
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
57 return oct_md5_result_to_str (buf);
6375
5fced7a5eee8 [project @ 2007-03-01 17:23:39 by dbateman]
dbateman
parents:
diff changeset
58 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
59
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
60 std::string
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
61 oct_md5_file (const std::string file)
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
62 {
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
63 std::string retval;
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
64
14153
06aa17228706 use gnulib::fopen
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
65 FILE *ifile = gnulib::fopen (file.c_str (), "rb");
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
66
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
67 if (ifile)
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
68 {
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
69 unsigned char buf[16];
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
70
11292
231e6d1b57d6 oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
71 int errflag = md5_stream (ifile, buf);
231e6d1b57d6 oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
72
11450
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 11293
diff changeset
73 gnulib::fclose (ifile);
11292
231e6d1b57d6 oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
74
231e6d1b57d6 oct_md5_file: close file after reading
John W. Eaton <jwe@octave.org>
parents: 10314
diff changeset
75 if (! errflag)
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
76 retval = oct_md5_result_to_str (buf);
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
77 else
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
78 (*current_liboctave_error_handler) ("internal error in md5_stream");
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
79 }
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
80 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14153
diff changeset
81 (*current_liboctave_error_handler) ("unable to open file '%s' for reading",
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14153
diff changeset
82 file.c_str ());
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
83
10025
acd5e9df38f8 use gnuplib crypto/md5 module
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
84 return retval;
6383
65e9cf5c7718 [project @ 2007-03-05 22:03:31 by dbateman]
dbateman
parents: 6375
diff changeset
85 }