diff --git a/src/IO.f90 b/src/IO.f90 index 5dbbf8563..2884eab33 100644 --- a/src/IO.f90 +++ b/src/IO.f90 @@ -448,6 +448,9 @@ subroutine IO_error(error_ID,el,ip,g,instance,ext_msg) msg = 'invalid character for float:' case (113) msg = 'invalid character for logical:' + case (114) + msg = 'cannot decode base64 string:' + !-------------------------------------------------------------------------------------------------- ! lattice error messages case (130) diff --git a/src/base64.f90 b/src/base64.f90 index 743afb5a7..2d2d4d010 100644 --- a/src/base64.f90 +++ b/src/base64.f90 @@ -70,22 +70,26 @@ function base64_to_bytes(base64_str,s,e) result(bytes) s, & !< start (in bytes) e !< end (in bytes) - integer(pLongInt) :: s_bytes, e_bytes - integer(C_SIGNED_CHAR), dimension(:), allocatable :: bytes, bytes_raw + integer(pLongInt) :: s_bytes, e_bytes, s_str, e_str + integer(C_SIGNED_CHAR), dimension(:), allocatable :: bytes - if(.not. valid_base64(base64_str)) error stop 'invalid base64' + if(.not. valid_base64(base64_str)) call IO_error(114,'invalid character') if(present(s)) then - if(s<1_pLongInt) error stop 'invalid s' - s_bytes = s + if(s<1_pLongInt) call IO_error(114, 's out of range') + s_str = ((s-1_pLongInt)/3_pLongInt)*4_pLongInt + 1_pLongInt + s_bytes = mod(s-1_pLongInt,3_pLongInt) + 1_pLongInt else - s_bytes = 1 + s_str = 1_pLongInt + s_bytes = 1_pLongInt endif if(present(e)) then - if(e>base64_nByte(len(base64_str,kind=pLongInt))) error stop 'invalid e' + if(e>base64_nByte(len(base64_str,kind=pLongInt))) call IO_error(114, 'e out of range') + e_str = ((e-1_pLongInt)/3_pLongInt)*4_pLongInt + 4_pLongInt e_bytes = e else + e_str = len(base64_str,kind=pLongInt) e_bytes = base64_nByte(len(base64_str,kind=pLongInt)) if(base64_str(len(base64_str)-0_pLongInt:len(base64_str)-0_pLongInt) == '=') & e_bytes = e_bytes -1_pLongInt @@ -93,9 +97,10 @@ function base64_to_bytes(base64_str,s,e) result(bytes) e_bytes = e_bytes -1_pLongInt endif - ! ToDo: inefficient for s_>>1 or e_<