Mercurial > octave
annotate liboctave/util/oct-base64.cc @ 25704:96584a825b0f stable
avoid alignment warning on solaris systems (bug #54389)
* oct-base64.cc (base64_decode): Declare pointer to output as double.
Cast address of pointer to char ** in call to
octave_base64_decode_alloc_wrapper instead of in call to std::copy.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 30 Jul 2018 15:20:23 -0400 |
parents | 6652d3823428 |
children | 29d89cd3d950 |
rev | line source |
---|---|
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2012-2018 John W. Eaton |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23748
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23748
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23748
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21213
diff
changeset
|
24 # include "config.h" |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
25 #endif |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 #include <algorithm> |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
29 #include "Array.h" |
21892
8fcc81df840c
hide gnulib base64 function header
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
30 #include "base64-wrappers.h" |
21213
f7d1050b9b53
maint: Clean up various usages of #ifdef.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
31 #include "oct-base64.h" |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
33 namespace octave |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
34 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
35 bool |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
36 base64_encode (const char *inc, const size_t inlen, char **out) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
37 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
38 bool ret = false; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
39 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
40 size_t outlen = octave_base64_encode_alloc_wrapper (inc, inlen, out); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
41 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
42 if (! out) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
43 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
44 if (outlen == 0 && inlen != 0) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
45 (*current_liboctave_error_handler) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
46 ("base64_encode: input array too large"); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
47 else |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
48 (*current_liboctave_error_handler) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
49 ("base64_encode: memory allocation error"); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
50 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
51 else |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
52 ret = true; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
53 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
54 return ret; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
55 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
56 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
57 Array<double> |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
58 base64_decode (const std::string& str) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
59 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
60 Array<double> retval; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
61 |
25704
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
62 double *out; |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
63 size_t outlen; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
64 |
25704
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
65 bool ok |
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
66 = octave_base64_decode_alloc_wrapper (str.data (), str.length (), |
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
67 reinterpret_cast<char **> (&out), |
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
68 &outlen); |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
69 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
70 if (! ok) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
71 (*current_liboctave_error_handler) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
72 ("base64_decode: input was not valid base64"); |
25704
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
73 |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
74 if (! out) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
75 (*current_liboctave_error_handler) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
76 ("base64_decode: memory allocation error"); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
77 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
78 if ((outlen % (sizeof (double) / sizeof (char))) != 0) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
79 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
80 ::free (out); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
81 (*current_liboctave_error_handler) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
82 ("base64_decode: incorrect input size"); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
83 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
84 else |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
85 { |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
86 octave_idx_type len = (outlen * sizeof (char)) / sizeof (double); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
87 retval.resize (dim_vector (1, len)); |
25704
96584a825b0f
avoid alignment warning on solaris systems (bug #54389)
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
88 std::copy (out, out + len, retval.fortran_vec ()); |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
89 ::free (out); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
90 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
91 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
92 return retval; |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
93 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
94 } |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
95 |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
96 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
97 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 bool |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 octave_base64_encode (const char *inc, const size_t inlen, char **out) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 { |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
101 return octave::base64_encode (inc, inlen, out); |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 } |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 Array<double> |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 octave_base64_decode (const std::string& str) |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 { |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
107 return octave::base64_decode (str); |
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
108 } |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
109 |
23748
6e86d3b5a063
move base64 encode and decode functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23447
diff
changeset
|
110 #endif |