diff options
| author | Gerd Moellmann | 2000-04-03 20:48:22 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-04-03 20:48:22 +0000 |
| commit | 3d6c79c5fa74096f18a15229e23a34ca787eb5af (patch) | |
| tree | 37eaf495418c431a41d7540f3accf1f80f415789 /src | |
| parent | c0510d271228c665d595de6aec4f12379954526a (diff) | |
| download | emacs-3d6c79c5fa74096f18a15229e23a34ca787eb5af.tar.gz emacs-3d6c79c5fa74096f18a15229e23a34ca787eb5af.zip | |
(Fbase64_decode_region, Fbase64_decode_string): Signal
an error if decoding fails.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 20 |
1 files changed, 10 insertions, 10 deletions
| @@ -3239,7 +3239,7 @@ DEFUN ("base64-decode-region", Fbase64_decode_region, Sbase64_decode_region, | |||
| 3239 | 2, 2, "r", | 3239 | 2, 2, "r", |
| 3240 | "Base64-decode the region between BEG and END.\n\ | 3240 | "Base64-decode the region between BEG and END.\n\ |
| 3241 | Return the length of the decoded text.\n\ | 3241 | Return the length of the decoded text.\n\ |
| 3242 | If the region can't be decoded, return nil and don't modify the buffer.") | 3242 | If the region can't be decoded, signal an error and don't modify the buffer.") |
| 3243 | (beg, end) | 3243 | (beg, end) |
| 3244 | Lisp_Object beg, end; | 3244 | Lisp_Object beg, end; |
| 3245 | { | 3245 | { |
| @@ -3271,7 +3271,7 @@ If the region can't be decoded, return nil and don't modify the buffer.") | |||
| 3271 | /* The decoding wasn't possible. */ | 3271 | /* The decoding wasn't possible. */ |
| 3272 | if (length > MAX_ALLOCA) | 3272 | if (length > MAX_ALLOCA) |
| 3273 | xfree (decoded); | 3273 | xfree (decoded); |
| 3274 | return Qnil; | 3274 | error ("Base64 decoding failed"); |
| 3275 | } | 3275 | } |
| 3276 | 3276 | ||
| 3277 | /* Now we have decoded the region, so we insert the new contents | 3277 | /* Now we have decoded the region, so we insert the new contents |
| @@ -3286,7 +3286,7 @@ If the region can't be decoded, return nil and don't modify the buffer.") | |||
| 3286 | inserted_chars = PT - (XFASTINT (beg) + 1); | 3286 | inserted_chars = PT - (XFASTINT (beg) + 1); |
| 3287 | if (length > MAX_ALLOCA) | 3287 | if (length > MAX_ALLOCA) |
| 3288 | xfree (decoded); | 3288 | xfree (decoded); |
| 3289 | /* At first delete the original text. This never cause byte | 3289 | /* At first delete the original text. This never causes byte |
| 3290 | combining. */ | 3290 | combining. */ |
| 3291 | del_range_both (PT + 1, PT_BYTE + 1, XFASTINT (end) + inserted_chars + 2, | 3291 | del_range_both (PT + 1, PT_BYTE + 1, XFASTINT (end) + inserted_chars + 2, |
| 3292 | iend + decoded_length + 2, 1); | 3292 | iend + decoded_length + 2, 1); |
| @@ -3309,8 +3309,8 @@ If the region can't be decoded, return nil and don't modify the buffer.") | |||
| 3309 | 3309 | ||
| 3310 | DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, | 3310 | DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, |
| 3311 | 1, 1, 0, | 3311 | 1, 1, 0, |
| 3312 | "Base64-decode STRING and return the result.") | 3312 | "Base64-decode STRING and return the result.") |
| 3313 | (string) | 3313 | (string) |
| 3314 | Lisp_Object string; | 3314 | Lisp_Object string; |
| 3315 | { | 3315 | { |
| 3316 | char *decoded; | 3316 | char *decoded; |
| @@ -3329,15 +3329,15 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, | |||
| 3329 | decoded_length = base64_decode_1 (XSTRING (string)->data, decoded, length); | 3329 | decoded_length = base64_decode_1 (XSTRING (string)->data, decoded, length); |
| 3330 | if (decoded_length > length) | 3330 | if (decoded_length > length) |
| 3331 | abort (); | 3331 | abort (); |
| 3332 | 3332 | else if (decoded_length >= 0) | |
| 3333 | if (decoded_length < 0) | ||
| 3334 | /* The decoding wasn't possible. */ | ||
| 3335 | decoded_string = Qnil; | ||
| 3336 | else | ||
| 3337 | decoded_string = make_string (decoded, decoded_length); | 3333 | decoded_string = make_string (decoded, decoded_length); |
| 3334 | else | ||
| 3335 | decoded_string = Qnil; | ||
| 3338 | 3336 | ||
| 3339 | if (length > MAX_ALLOCA) | 3337 | if (length > MAX_ALLOCA) |
| 3340 | xfree (decoded); | 3338 | xfree (decoded); |
| 3339 | if (!STRINGP (decoded_string)) | ||
| 3340 | error ("Base64 decoding failed"); | ||
| 3341 | 3341 | ||
| 3342 | return decoded_string; | 3342 | return decoded_string; |
| 3343 | } | 3343 | } |