clang -cc1 -cc1 -triple i386-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name array_extensions.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu i686 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/joels/Current/lispbm -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -I .//include -I .//include/extensions -I .//src -I .//utils -I platform/linux/include -D _PRELUDE -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -std=c99 -fdebug-compilation-dir=/home/joels/Current/lispbm -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/joels/Current/lispbm/test_reports/version_0.41.0/scan-build/2026-10-16-144956-1359644-1 -x c src/extensions/array_extensions.c
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | #include "extensions/array_extensions.h" |
| 20 | |
| 21 | #include "extensions.h" |
| 22 | #include "symrepr.h" |
| 23 | #include "lbm_memory.h" |
| 24 | |
| 25 | #include <math.h> |
| 26 | |
| 27 | #ifdef LBM_OPT_ARRAY_EXTENSIONS_SIZE |
| 28 | #pragma GCC optimize ("-Os") |
| 29 | #endif |
| 30 | #ifdef LBM_OPT_ARRAY_EXTENSIONS_SIZE_AGGRESSIVE |
| 31 | #pragma GCC optimize ("-Oz") |
| 32 | #endif |
| 33 | |
| 34 | static lbm_uint little_endian = 0; |
| 35 | static lbm_uint big_endian = 0; |
| 36 | static lbm_uint dbc_sym = 0; |
| 37 | |
| 38 | static lbm_value array_extension_unsafe_free_array(lbm_value *args, lbm_uint argn); |
| 39 | static lbm_value array_extension_buffer_append_i8(lbm_value *args, lbm_uint argn); |
| 40 | static lbm_value array_extension_buffer_append_i16(lbm_value *args, lbm_uint argn); |
| 41 | static lbm_value array_extension_buffer_append_i32(lbm_value *args, lbm_uint argn); |
| 42 | static lbm_value array_extension_buffer_append_u8(lbm_value *args, lbm_uint argn); |
| 43 | static lbm_value array_extension_buffer_append_u16(lbm_value *args, lbm_uint argn); |
| 44 | static lbm_value array_extension_buffer_append_u24(lbm_value *args, lbm_uint argn); |
| 45 | static lbm_value array_extension_buffer_append_u32(lbm_value *args, lbm_uint argn); |
| 46 | static lbm_value array_extension_buffer_append_f32(lbm_value *args, lbm_uint argn); |
| 47 | |
| 48 | static lbm_value array_extension_buffer_get_i8(lbm_value *args, lbm_uint argn); |
| 49 | static lbm_value array_extension_buffer_get_i16(lbm_value *args, lbm_uint argn); |
| 50 | static lbm_value array_extension_buffer_get_i32(lbm_value *args, lbm_uint argn); |
| 51 | static lbm_value array_extension_buffer_get_u8(lbm_value *args, lbm_uint argn); |
| 52 | static lbm_value array_extension_buffer_get_u16(lbm_value *args, lbm_uint argn); |
| 53 | static lbm_value array_extension_buffer_get_u24(lbm_value *args, lbm_uint argn); |
| 54 | static lbm_value array_extension_buffer_get_u32(lbm_value *args, lbm_uint argn); |
| 55 | static lbm_value array_extension_buffer_get_f32(lbm_value *args, lbm_uint argn); |
| 56 | |
| 57 | static lbm_value array_extension_buffer_length(lbm_value *args, lbm_uint argn); |
| 58 | |
| 59 | static lbm_value array_extensions_bufclear(lbm_value *args, lbm_uint argn); |
| 60 | static lbm_value array_extensions_bufcpy(lbm_value *args, lbm_uint argn); |
| 61 | static lbm_value array_extensions_bufset_bit(lbm_value *args, lbm_uint argn); |
| 62 | |
| 63 | static lbm_value array_extensions_bufset_bits_u(lbm_value *args, lbm_uint argn); |
| 64 | static lbm_value array_extensions_bufset_bits_i(lbm_value *args, lbm_uint argn); |
| 65 | static lbm_value array_extensions_bufget_bits_u(lbm_value *args, lbm_uint argn); |
| 66 | static lbm_value array_extensions_bufget_bits_i(lbm_value *args, lbm_uint argn); |
| 67 | static lbm_value array_extensions_bufset_bits_f32(lbm_value *args, lbm_uint argn); |
| 68 | static lbm_value array_extensions_bufget_bits_f32(lbm_value *args, lbm_uint argn); |
| 69 | |
| 70 | void lbm_array_extensions_init(void) { |
| 71 | |
| 72 | lbm_add_symbol_const("little-endian", &little_endian); |
| 73 | lbm_add_symbol_const("big-endian", &big_endian); |
| 74 | lbm_add_symbol_const("dbc", &dbc_sym); |
| 75 | |
| 76 | lbm_add_extension("free", array_extension_unsafe_free_array); |
| 77 | lbm_add_extension("bufset-i8", array_extension_buffer_append_i8); |
| 78 | lbm_add_extension("bufset-i16", array_extension_buffer_append_i16); |
| 79 | lbm_add_extension("bufset-i32", array_extension_buffer_append_i32); |
| 80 | lbm_add_extension("bufset-u8", array_extension_buffer_append_u8); |
| 81 | lbm_add_extension("bufset-u16", array_extension_buffer_append_u16); |
| 82 | lbm_add_extension("bufset-u24", array_extension_buffer_append_u24); |
| 83 | lbm_add_extension("bufset-u32", array_extension_buffer_append_u32); |
| 84 | lbm_add_extension("bufset-f32", array_extension_buffer_append_f32); |
| 85 | |
| 86 | lbm_add_extension("bufget-i8", array_extension_buffer_get_i8); |
| 87 | lbm_add_extension("bufget-i16", array_extension_buffer_get_i16); |
| 88 | lbm_add_extension("bufget-i32", array_extension_buffer_get_i32); |
| 89 | lbm_add_extension("bufget-u8", array_extension_buffer_get_u8); |
| 90 | lbm_add_extension("bufget-u16", array_extension_buffer_get_u16); |
| 91 | lbm_add_extension("bufget-u24", array_extension_buffer_get_u24); |
| 92 | lbm_add_extension("bufget-u32", array_extension_buffer_get_u32); |
| 93 | lbm_add_extension("bufget-f32", array_extension_buffer_get_f32); |
| 94 | |
| 95 | lbm_add_extension("buflen", array_extension_buffer_length); |
| 96 | lbm_add_extension("bufclear", array_extensions_bufclear); |
| 97 | lbm_add_extension("bufcpy", array_extensions_bufcpy); |
| 98 | lbm_add_extension("bufset-bit", array_extensions_bufset_bit); |
| 99 | |
| 100 | lbm_add_extension("bufset-bits-u", array_extensions_bufset_bits_u); |
| 101 | lbm_add_extension("bufset-bits-i", array_extensions_bufset_bits_i); |
| 102 | lbm_add_extension("bufget-bits-u", array_extensions_bufget_bits_u); |
| 103 | lbm_add_extension("bufget-bits-i", array_extensions_bufget_bits_i); |
| 104 | lbm_add_extension("bufset-bits-f32", array_extensions_bufset_bits_f32); |
| 105 | lbm_add_extension("bufget-bits-f32", array_extensions_bufget_bits_f32); |
| 106 | } |
| 107 | |
| 108 | lbm_value array_extension_unsafe_free_array(lbm_value *args, lbm_uint argn) { |
| 109 | lbm_value res = ENC_SYM_EERROR; |
| 110 | if (argn == 1) { |
| 111 | if (lbm_is_array_rw(args[0])) { |
| 112 | if (lbm_heap_explicit_free_array(args[0])) { |
| 113 | res = ENC_SYM_TRUE; |
| 114 | } else { |
| 115 | res = ENC_SYM_NIL; |
| 116 | } |
| 117 | } else { |
| 118 | res = ENC_SYM_TERROR; |
| 119 | } |
| 120 | } |
| 121 | return res; |
| 122 | } |
| 123 | |
| 124 | static bool decode_append_args(lbm_value *error, lbm_value *args, lbm_uint argn, lbm_uint *index, bool *be, lbm_uint *a_size, uint8_t **a_data) { |
| 125 | *be = true; |
| 126 | *error = ENC_SYM_EERROR; |
| 127 | bool res = false; |
| 128 | switch(argn) { |
| 129 | case 4: |
| 130 | if (lbm_type_of(args[3]) == LBM_TYPE_SYMBOL && |
| 131 | lbm_dec_sym(args[3]) == little_endian) { |
| 132 | *be = false; |
| 133 | } |
| 134 | |
| 135 | case 3: { |
| 136 | lbm_array_header_t *array = lbm_dec_array_rw(args[0]); |
| 137 | if(array && |
| 138 | lbm_is_number(args[1]) && |
| 139 | lbm_is_number(args[2])) { |
| 140 | *a_size = array->size; |
| 141 | *a_data = (uint8_t*)array->data; |
| 142 | *index = lbm_dec_as_u32(args[1]); |
| 143 | res = true; |
| 144 | } else { |
| 145 | *error = ENC_SYM_TERROR; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | return res; |
| 150 | } |
| 151 | |
| 152 | static bool buffer_append_bytes(uint8_t *data, lbm_uint d_size, bool be, lbm_uint index, lbm_uint nbytes, lbm_uint value) { |
| 153 | |
| 154 | lbm_uint last_index = index + (nbytes - 1); |
| 155 | bool res = false; |
| 156 | if (last_index < d_size) { |
| 157 | res = true; |
| 158 | switch(nbytes) { |
| 159 | case 1: |
| 160 | data[index] = (uint8_t) value; |
| 161 | break; |
| 162 | case 2: |
| 163 | if (be) { |
| 164 | data[index+1] = (uint8_t)value; |
| 165 | data[index] = (uint8_t)(value >> 8); |
| 166 | } else { |
| 167 | data[index] = (uint8_t)value; |
| 168 | data[index +1] = (uint8_t)(value >> 8); |
| 169 | } |
| 170 | break; |
| 171 | case 3: |
| 172 | if (be) { |
| 173 | data[index+2] = (uint8_t)value; |
| 174 | data[index+1] = (uint8_t)(value >> 8); |
| 175 | data[index] = (uint8_t)(value >> 16); |
| 176 | } else { |
| 177 | data[index] = (uint8_t)value; |
| 178 | data[index+1] = (uint8_t)(value >> 8); |
| 179 | data[index+2] = (uint8_t)(value >> 16); |
| 180 | } |
| 181 | break; |
| 182 | default: |
| 183 | if (be) { |
| 184 | data[index+3] = (uint8_t) value; |
| 185 | data[index+2] = (uint8_t) (value >> 8); |
| 186 | data[index+1] = (uint8_t) (value >> 16); |
| 187 | data[index] = (uint8_t) (value >> 24); |
| 188 | } else { |
| 189 | data[index] = (uint8_t) value; |
| 190 | data[index+1] = (uint8_t) (value >> 8); |
| 191 | data[index+2] = (uint8_t) (value >> 16); |
| 192 | data[index+3] = (uint8_t) (value >> 24); |
| 193 | } |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | return res; |
| 198 | } |
| 199 | |
| 200 | lbm_value array_extension_buffer_append_i8(lbm_value *args, lbm_uint argn) { |
| 201 | |
| 202 | lbm_value res = ENC_SYM_EERROR; |
| 203 | uint8_t *data = NULL; |
| 204 | lbm_uint d_size = 0; |
| 205 | bool be = false; |
| 206 | lbm_uint index = 0; |
| 207 | |
| 208 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 209 | if (buffer_append_bytes(data, d_size, be, index, 1, (lbm_uint)lbm_dec_as_i32(args[2]))) { |
| 210 | res = ENC_SYM_TRUE; |
| 211 | } |
| 212 | } |
| 213 | return res; |
| 214 | } |
| 215 | |
| 216 | lbm_value array_extension_buffer_append_i16(lbm_value *args, lbm_uint argn) { |
| 217 | |
| 218 | lbm_value res = ENC_SYM_EERROR; |
| 219 | uint8_t *data = NULL; |
| 220 | lbm_uint d_size = 0; |
| 221 | bool be = false; |
| 222 | lbm_uint index = 0; |
| 223 | |
| 224 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 225 | if (buffer_append_bytes(data, d_size, be, index, 2, (lbm_uint)lbm_dec_as_i32(args[2]))) { |
| 226 | res = ENC_SYM_TRUE; |
| 227 | } |
| 228 | } |
| 229 | return res; |
| 230 | } |
| 231 | |
| 232 | lbm_value array_extension_buffer_append_i32(lbm_value *args, lbm_uint argn) { |
| 233 | |
| 234 | lbm_value res = ENC_SYM_EERROR; |
| 235 | uint8_t *data = NULL; |
| 236 | lbm_uint d_size = 0; |
| 237 | bool be = false; |
| 238 | lbm_uint index = 0; |
| 239 | |
| 240 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 241 | if (buffer_append_bytes(data, d_size, be, index, 4, (lbm_uint)lbm_dec_as_i32(args[2]))) { |
| 242 | res = ENC_SYM_TRUE; |
| 243 | } |
| 244 | } |
| 245 | return res; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | lbm_value array_extension_buffer_append_u8(lbm_value *args, lbm_uint argn) { |
| 250 | |
| 251 | lbm_value res = ENC_SYM_EERROR; |
| 252 | uint8_t *data = NULL; |
| 253 | lbm_uint d_size = 0; |
| 254 | bool be = false; |
| 255 | lbm_uint index = 0; |
| 256 | |
| 257 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 258 | if (buffer_append_bytes(data, d_size, be, index, 1, (lbm_uint)lbm_dec_as_u32(args[2]))) { |
| 259 | res = ENC_SYM_TRUE; |
| 260 | } |
| 261 | } |
| 262 | return res; |
| 263 | } |
| 264 | |
| 265 | lbm_value array_extension_buffer_append_u16(lbm_value *args, lbm_uint argn) { |
| 266 | |
| 267 | lbm_value res = ENC_SYM_EERROR; |
| 268 | uint8_t *data = NULL; |
| 269 | lbm_uint d_size = 0; |
| 270 | bool be = false; |
| 271 | lbm_uint index = 0; |
| 272 | |
| 273 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 274 | if (buffer_append_bytes(data, d_size, be, index, 2, (lbm_uint)lbm_dec_as_u32(args[2]))) { |
| 275 | res = ENC_SYM_TRUE; |
| 276 | } |
| 277 | } |
| 278 | return res; |
| 279 | } |
| 280 | |
| 281 | lbm_value array_extension_buffer_append_u24(lbm_value *args, lbm_uint argn) { |
| 282 | |
| 283 | lbm_value res = ENC_SYM_EERROR; |
| 284 | uint8_t *data = NULL; |
| 285 | lbm_uint d_size = 0; |
| 286 | bool be = false; |
| 287 | lbm_uint index = 0; |
| 288 | |
| 289 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 290 | if (buffer_append_bytes(data, d_size, be, index, 3, (lbm_uint)lbm_dec_as_u32(args[2]))) { |
| 291 | res = ENC_SYM_TRUE; |
| 292 | } |
| 293 | } |
| 294 | return res; |
| 295 | } |
| 296 | |
| 297 | lbm_value array_extension_buffer_append_u32(lbm_value *args, lbm_uint argn) { |
| 298 | |
| 299 | lbm_value res = ENC_SYM_EERROR; |
| 300 | uint8_t *data = NULL; |
| 301 | lbm_uint d_size = 0; |
| 302 | bool be = false; |
| 303 | lbm_uint index = 0; |
| 304 | |
| 305 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 306 | if (buffer_append_bytes(data, d_size, be, index, 4, (lbm_uint)lbm_dec_as_u32(args[2]))) { |
| 307 | res = ENC_SYM_TRUE; |
| 308 | } |
| 309 | } |
| 310 | return res; |
| 311 | } |
| 312 | |
| 313 | static lbm_uint float_to_u(float number) { |
| 314 | |
| 315 | |
| 316 | if (fabsf(number) < 1.5e-38) { |
| 317 | number = 0.0; |
| 318 | } |
| 319 | |
| 320 | int e = 0; |
| 321 | float sig = frexpf(number, &e); |
| 322 | float sig_abs = fabsf(sig); |
| 323 | uint32_t sig_i = 0; |
| 324 | |
| 325 | if (sig_abs >= 0.5) { |
| 326 | sig_i = (uint32_t)((sig_abs - 0.5f) * 2.0f * 8388608.0f); |
| 327 | e += 126; |
| 328 | } |
| 329 | |
| 330 | uint32_t res = (((uint32_t)e & 0xFFu) << 23) | (uint32_t)(sig_i & 0x7FFFFFu); |
| 331 | if (sig < 0) { |
| 332 | res |= 1U << 31; |
| 333 | } |
| 334 | |
| 335 | return res; |
| 336 | } |
| 337 | |
| 338 | static lbm_float u_to_float(uint32_t v) { |
| 339 | |
| 340 | int e = (v >> 23) & 0xFF; |
| 341 | uint32_t sig_i = v & 0x7FFFFF; |
| 342 | bool neg = v & (1U << 31); |
| 343 | |
| 344 | float sig = 0.0; |
| 345 | if (e != 0 || sig_i != 0) { |
| 346 | sig = (float)sig_i / (8388608.0f * 2.0f) + 0.5f; |
| 347 | e -= 126; |
| 348 | } |
| 349 | |
| 350 | if (neg) { |
| 351 | sig = -sig; |
| 352 | } |
| 353 | |
| 354 | return ldexpf(sig, e); |
| 355 | } |
| 356 | |
| 357 | lbm_value array_extension_buffer_append_f32(lbm_value *args, lbm_uint argn) { |
| 358 | |
| 359 | lbm_value res = ENC_SYM_EERROR; |
| 360 | uint8_t *data = NULL; |
| 361 | lbm_uint d_size = 0; |
| 362 | bool be = false; |
| 363 | lbm_uint index = 0; |
| 364 | |
| 365 | if (decode_append_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 366 | if (buffer_append_bytes(data, d_size, be, index, 4, (lbm_uint)float_to_u(lbm_dec_as_float(args[2])))) { |
| 367 | res = ENC_SYM_TRUE; |
| 368 | } |
| 369 | } |
| 370 | return res; |
| 371 | } |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | static bool decode_get_args(lbm_value *error, lbm_value *args, lbm_uint argn, lbm_uint *index, bool *be, lbm_uint *a_size, uint8_t **a_data) { |
| 377 | bool res = false; |
| 378 | |
| 379 | *be=true; |
| 380 | |
| 381 | switch(argn) { |
| 382 | case 3: |
| 383 | if (lbm_type_of(args[2]) == LBM_TYPE_SYMBOL && |
| 384 | lbm_dec_sym(args[2]) == little_endian) { |
| 385 | *be = false; |
| 386 | } |
| 387 | |
| 388 | case 2: { |
| 389 | lbm_array_header_t *array = lbm_dec_array_r(args[0]); |
| 390 | if (array && |
| 391 | lbm_is_number(args[1])) { |
| 392 | *a_size = array->size; |
| 393 | *a_data = (uint8_t*)array->data; |
| 394 | *index = lbm_dec_as_u32(args[1]); |
| 395 | res = true; |
| 396 | } else { |
| 397 | *error = ENC_SYM_TERROR; |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | return res; |
| 402 | } |
| 403 | |
| 404 | static bool buffer_get_uint(lbm_uint *r_value, uint8_t *data, lbm_uint d_size, bool be, lbm_uint index, lbm_uint nbytes) { |
| 405 | |
| 406 | bool res = false; |
| 407 | lbm_uint last_index = index + (nbytes - 1); |
| 408 | |
| 409 | if (last_index < d_size) { |
| 410 | lbm_uint value = 0; |
| 411 | res = true; |
| 412 | switch(nbytes) { |
| 413 | case 1: |
| 414 | value = (lbm_uint)data[index]; |
| 415 | break; |
| 416 | case 2: |
| 417 | if (be) { |
| 418 | value = |
| 419 | (lbm_uint) data[index+1] | |
| 420 | (lbm_uint) data[index] << 8; |
| 421 | } else { |
| 422 | value = |
| 423 | (lbm_uint) data[index] | |
| 424 | (lbm_uint) data[index+1] << 8; |
| 425 | } |
| 426 | break; |
| 427 | case 3: |
| 428 | if (be) { |
| 429 | value = |
| 430 | (lbm_uint) data[index+2] | |
| 431 | (lbm_uint) data[index+1] << 8 | |
| 432 | (lbm_uint) data[index] << 16; |
| 433 | } else { |
| 434 | value = |
| 435 | (lbm_uint) data[index] | |
| 436 | (lbm_uint) data[index+1] << 8 | |
| 437 | (lbm_uint) data[index+2] << 16; |
| 438 | } |
| 439 | break; |
| 440 | case 4: |
| 441 | if (be) { |
| 442 | value = |
| 443 | (uint32_t) data[index+3] | |
| 444 | (uint32_t) data[index+2] << 8 | |
| 445 | (uint32_t) data[index+1] << 16 | |
| 446 | (uint32_t) data[index] << 24; |
| 447 | } else { |
| 448 | value = |
| 449 | (uint32_t) data[index] | |
| 450 | (uint32_t) data[index+1] << 8 | |
| 451 | (uint32_t) data[index+2] << 16 | |
| 452 | (uint32_t) data[index+3] << 24; |
| 453 | } |
| 454 | break; |
| 455 | default: |
| 456 | res = false; |
| 457 | } |
| 458 | *r_value = value; |
| 459 | } |
| 460 | return res; |
| 461 | } |
| 462 | |
| 463 | |
| 464 | |
| 465 | lbm_value array_extension_buffer_get_i8(lbm_value *args, lbm_uint argn) { |
| 466 | lbm_value res = ENC_SYM_EERROR; |
| 467 | uint8_t *data = NULL; |
| 468 | lbm_uint d_size = 0; |
| 469 | bool be = false; |
| 470 | lbm_uint index = 0; |
| 471 | lbm_uint value = 0; |
| 472 | |
| 473 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 474 | if (buffer_get_uint(&value, data, d_size, be, index, 1)) { |
| 475 | res =lbm_enc_i((int8_t)value); |
| 476 | } |
| 477 | } |
| 478 | return res; |
| 479 | } |
| 480 | |
| 481 | lbm_value array_extension_buffer_get_i16(lbm_value *args, lbm_uint argn) { |
| 482 | lbm_value res = ENC_SYM_EERROR; |
| 483 | uint8_t *data = NULL; |
| 484 | lbm_uint d_size = 0; |
| 485 | bool be = false; |
| 486 | lbm_uint index = 0; |
| 487 | lbm_uint value = 0; |
| 488 | |
| 489 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 490 | if (buffer_get_uint(&value, data, d_size, be, index, 2)) { |
| 491 | res =lbm_enc_i((int16_t)value); |
| 492 | } |
| 493 | } |
| 494 | return res; |
| 495 | } |
| 496 | |
| 497 | lbm_value array_extension_buffer_get_i32(lbm_value *args, lbm_uint argn) { |
| 498 | lbm_value res = ENC_SYM_EERROR; |
| 499 | uint8_t *data = NULL; |
| 500 | lbm_uint d_size = 0; |
| 501 | bool be = false; |
| 502 | lbm_uint index = 0; |
| 503 | lbm_uint value = 0; |
| 504 | |
| 505 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 506 | if (buffer_get_uint(&value, data, d_size, be, index, 4)) { |
| 507 | res =lbm_enc_i((int32_t)value); |
| 508 | } |
| 509 | } |
| 510 | return res; |
| 511 | } |
| 512 | |
| 513 | lbm_value array_extension_buffer_get_u8(lbm_value *args, lbm_uint argn) { |
| 514 | lbm_value res = ENC_SYM_EERROR; |
| 515 | uint8_t *data = NULL; |
| 516 | lbm_uint d_size = 0; |
| 517 | bool be = false; |
| 518 | lbm_uint index = 0; |
| 519 | lbm_uint value = 0; |
| 520 | |
| 521 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 522 | if (buffer_get_uint(&value, data, d_size, be, index, 1)) { |
| 523 | res = lbm_enc_i((uint8_t)value); |
| 524 | } |
| 525 | } |
| 526 | return res; |
| 527 | } |
| 528 | |
| 529 | lbm_value array_extension_buffer_get_u16(lbm_value *args, lbm_uint argn) { |
| 530 | lbm_value res = ENC_SYM_EERROR; |
| 531 | uint8_t *data = NULL; |
| 532 | lbm_uint d_size = 0; |
| 533 | bool be = false; |
| 534 | lbm_uint index = 0; |
| 535 | lbm_uint value = 0; |
| 536 | |
| 537 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 538 | if (buffer_get_uint(&value, data, d_size, be, index, 2)) { |
| 539 | res = lbm_enc_i((uint16_t)value); |
| 540 | } |
| 541 | } |
| 542 | return res; |
| 543 | } |
| 544 | |
| 545 | lbm_value array_extension_buffer_get_u24(lbm_value *args, lbm_uint argn) { |
| 546 | lbm_value res = ENC_SYM_EERROR; |
| 547 | uint8_t *data = NULL; |
| 548 | lbm_uint d_size = 0; |
| 549 | bool be = false; |
| 550 | lbm_uint index = 0; |
| 551 | lbm_uint value = 0; |
| 552 | |
| 553 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 554 | if (buffer_get_uint(&value, data, d_size, be, index, 3)) { |
| 555 | res = lbm_enc_i((int32_t)value); |
| 556 | } |
| 557 | } |
| 558 | return res; |
| 559 | } |
| 560 | |
| 561 | lbm_value array_extension_buffer_get_u32(lbm_value *args, lbm_uint argn) { |
| 562 | lbm_value res = ENC_SYM_EERROR; |
| 563 | uint8_t *data = NULL; |
| 564 | lbm_uint d_size = 0; |
| 565 | bool be = false; |
| 566 | lbm_uint index = 0; |
| 567 | lbm_uint value = 0; |
| 568 | |
| 569 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 570 | if (buffer_get_uint(&value, data, d_size, be, index, 4)) { |
| 571 | res = lbm_enc_u32((uint32_t)value); |
| 572 | } |
| 573 | } |
| 574 | return res; |
| 575 | } |
| 576 | |
| 577 | lbm_value array_extension_buffer_get_f32(lbm_value *args, lbm_uint argn) { |
| 578 | lbm_value res = ENC_SYM_EERROR; |
| 579 | uint8_t *data = NULL; |
| 580 | lbm_uint d_size = 0; |
| 581 | bool be = false; |
| 582 | lbm_uint index = 0; |
| 583 | lbm_uint value = 0; |
| 584 | |
| 585 | if (decode_get_args(&res, args, argn, &index, &be, &d_size, &data)) { |
| 586 | if (buffer_get_uint(&value, data, d_size, be, index, 4)) { |
| 587 | res = lbm_enc_float(u_to_float((uint32_t)value)); |
| 588 | } |
| 589 | } |
| 590 | return res; |
| 591 | } |
| 592 | |
| 593 | lbm_value array_extension_buffer_length(lbm_value *args, lbm_uint argn) { |
| 594 | lbm_value res = ENC_SYM_EERROR; |
| 595 | lbm_array_header_t *array; |
| 596 | if (argn == 1 && |
| 597 | (array = lbm_dec_array_r(args[0])) && |
| 598 | lbm_heap_array_valid(args[0])) { |
| 599 | res = lbm_enc_i((lbm_int)array->size); |
| 600 | } |
| 601 | return res; |
| 602 | } |
| 603 | |
| 604 | |
| 605 | static lbm_value array_extensions_bufclear(lbm_value *args, lbm_uint argn) { |
| 606 | lbm_value res = ENC_SYM_EERROR; |
| 607 | if (argn >= 1 && argn <= 4) { |
| 608 | res = ENC_SYM_TERROR; |
| 609 | if (lbm_is_array_rw(args[0])) { |
| 610 | lbm_array_header_t *array = (lbm_array_header_t *)lbm_car(args[0]); |
| 611 | |
| 612 | uint8_t clear_byte = 0; |
| 613 | if (argn >= 2) { |
| 614 | if (!lbm_is_number(args[1])) { |
| 615 | return res; |
| 616 | } |
| 617 | clear_byte = (uint8_t)lbm_dec_as_u32(args[1]); |
| 618 | } |
| 619 | |
| 620 | uint32_t start = 0; |
| 621 | if (argn >= 3) { |
| 622 | if (!lbm_is_number(args[2])) { |
| 623 | return res; |
| 624 | } |
| 625 | uint32_t start_new = lbm_dec_as_u32(args[2]); |
| 626 | if (start_new < array->size) { |
| 627 | start = start_new; |
| 628 | } else { |
| 629 | return res; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | uint32_t len = (uint32_t)array->size - start; |
| 634 | if (argn >= 4) { |
| 635 | if (!lbm_is_number(args[3])) { |
| 636 | return res; |
| 637 | } |
| 638 | uint32_t len_new = lbm_dec_as_u32(args[3]); |
| 639 | if (len_new <= len) { |
| 640 | len = len_new; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | memset((char*)array->data + start, clear_byte, len); |
| 645 | res = ENC_SYM_TRUE; |
| 646 | } |
| 647 | } |
| 648 | return res; |
| 649 | } |
| 650 | |
| 651 | static lbm_value array_extensions_bufcpy(lbm_value *args, lbm_uint argn) { |
| 652 | lbm_value res = ENC_SYM_EERROR; |
| 653 | |
| 654 | if (argn == 5) { |
| 655 | res = ENC_SYM_TERROR; |
| 656 | if (lbm_is_array_rw(args[0]) && lbm_is_number(args[1]) && |
| 657 | lbm_is_array_r(args[2]) && lbm_is_number(args[3]) &&lbm_is_number(args[4])) { |
| 658 | lbm_array_header_t *array1 = (lbm_array_header_t *)lbm_car(args[0]); |
| 659 | |
| 660 | uint32_t start1 = lbm_dec_as_u32(args[1]); |
| 661 | |
| 662 | lbm_array_header_t *array2 = (lbm_array_header_t *)lbm_car(args[2]); |
| 663 | |
| 664 | uint32_t start2 = lbm_dec_as_u32(args[3]); |
| 665 | uint32_t len = lbm_dec_as_u32(args[4]); |
| 666 | |
| 667 | if (start1 < array1->size && start2 < array2->size) { |
| 668 | if (len > (array1->size - start1)) { |
| 669 | len = ((uint32_t)array1->size - start1); |
| 670 | } |
| 671 | if (len > (array2->size - start2)) { |
| 672 | len = ((uint32_t)array2->size - start2); |
| 673 | } |
| 674 | |
| 675 | memcpy((char*)array1->data + start1, (char*)array2->data + start2, len); |
| 676 | } |
| 677 | res = ENC_SYM_TRUE; |
| 678 | } |
| 679 | } |
| 680 | return res; |
| 681 | } |
| 682 | |
| 683 | static lbm_value array_extensions_bufset_bit(lbm_value *args, lbm_uint argn) { |
| 684 | lbm_value res = ENC_SYM_EERROR; |
| 685 | |
| 686 | if (argn == 3) { |
| 687 | res = ENC_SYM_TERROR; |
| 688 | if (lbm_is_array_rw(args[0]) && |
| 689 | lbm_is_number(args[1]) && lbm_is_number(args[2])) { |
| 690 | lbm_array_header_t *array = (lbm_array_header_t *)lbm_car(args[0]); |
| 691 | |
| 692 | unsigned int pos = lbm_dec_as_u32(args[1]); |
| 693 | unsigned int bit = lbm_dec_as_u32(args[2]) ? 1 : 0; |
| 694 | |
| 695 | unsigned int bytepos = pos / 8; |
| 696 | |
| 697 | if (bytepos < array->size) { |
| 698 | unsigned int bitpos = pos % 8; |
| 699 | ((uint8_t*)array->data)[bytepos] &= (uint8_t)~(1 << bitpos); |
| 700 | ((uint8_t*)array->data)[bytepos] |= (uint8_t)(bit << bitpos); |
| 701 | } |
| 702 | |
| 703 | res = ENC_SYM_TRUE; |
| 704 | } |
| 705 | } |
| 706 | return res; |
| 707 | } |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | static lbm_uint dbc_bit_pos(lbm_uint pos) { |
| 715 | return (7 - (pos % 8)) + (pos / 8) * 8; |
| 716 | } |
| 717 | |
| 718 | static int64_t sign_extend64(uint64_t v, lbm_uint len) { |
| 719 | if (len >= 64) return (int64_t)v; |
| 720 | uint64_t sign_bit = (uint64_t)1 << (len - 1); |
| 721 | return (int64_t)((v ^ sign_bit) - sign_bit); |
| 722 | } |
| 723 | |
| 724 | static void decode_bits_flags(lbm_value *args, lbm_uint argn, lbm_uint fixed_argn, bool *be, bool *dbc) { |
| 725 | *be = true; |
| 726 | *dbc = false; |
| 727 | for (lbm_uint i = fixed_argn; i < argn; i ++) { |
| 9 | | Assuming 'i' is < 'argn' | |
|
| 10 | | Loop condition is true. Entering loop body | |
|
| 16 | | Assuming 'i' is >= 'argn' | |
|
| 17 | | Loop condition is false. Execution continues on line 727 | |
|
| 728 | if (lbm_type_of(args[i]) == LBM_TYPE_SYMBOL) { |
| 11 | | Assuming the condition is true | |
|
| |
| 729 | lbm_uint s = lbm_dec_sym(args[i]); |
| 730 | if (s == little_endian) *be = false; |
| 13 | | Assuming 's' is equal to 'little_endian' | |
|
| |
| 15 | | The value 0 is assigned to 'be', which participates in a condition later | |
|
| 731 | else if (s == big_endian) *be = true; |
| 732 | else if (s == dbc_sym) *dbc = true; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | static bool decode_bits_get_args(lbm_value *error, lbm_value *args, lbm_uint argn, |
| 738 | lbm_uint *pos, lbm_uint *len, bool *be, bool *dbc, |
| 739 | lbm_uint *a_size, uint8_t **a_data) { |
| 740 | *error = ENC_SYM_EERROR; |
| 741 | if (argn < 3 || argn > 5) return false; |
| 742 | lbm_array_header_t *array = lbm_dec_array_r(args[0]); |
| 743 | if (!(array && lbm_is_number(args[1]) && lbm_is_number(args[2]))) { |
| 744 | *error = ENC_SYM_TERROR; |
| 745 | return false; |
| 746 | } |
| 747 | *a_size = array->size; |
| 748 | *a_data = (uint8_t*)array->data; |
| 749 | *pos = lbm_dec_as_u32(args[1]); |
| 750 | *len = lbm_dec_as_u32(args[2]); |
| 751 | decode_bits_flags(args, argn, 3, be, dbc); |
| 752 | return true; |
| 753 | } |
| 754 | |
| 755 | static bool decode_bits_set_args(lbm_value *error, lbm_value *args, lbm_uint argn, |
| 756 | lbm_uint *pos, lbm_uint *len, bool *be, bool *dbc, |
| 757 | lbm_uint *a_size, uint8_t **a_data) { |
| 758 | *error = ENC_SYM_EERROR; |
| 759 | if (argn < 4 || argn > 6) return false; |
| 760 | lbm_array_header_t *array = lbm_dec_array_rw(args[0]); |
| 761 | if (!(array && lbm_is_number(args[1]) && lbm_is_number(args[2]) && lbm_is_number(args[3]))) { |
| 762 | *error = ENC_SYM_TERROR; |
| 763 | return false; |
| 764 | } |
| 765 | *a_size = array->size; |
| 766 | *a_data = (uint8_t*)array->data; |
| 767 | *pos = lbm_dec_as_u32(args[1]); |
| 768 | *len = lbm_dec_as_u32(args[2]); |
| 769 | decode_bits_flags(args, argn, 4, be, dbc); |
| 770 | return true; |
| 771 | } |
| 772 | |
| 773 | static bool bits_insert(uint8_t *data, lbm_uint d_size, lbm_uint pos, lbm_uint len, |
| 774 | bool be, bool dbc, uint64_t number) { |
| 775 | if (len == 0 || len > 64) return false; |
| 776 | if (dbc && be) pos = dbc_bit_pos(pos); |
| 777 | if (be) number <<= (64 - len); |
| 778 | |
| 779 | lbm_uint bitcnt = 0, remaining = len; |
| 780 | while (remaining > 0) { |
| 781 | lbm_uint bytepos = (pos + bitcnt) / 8; |
| 782 | if (bytepos >= d_size) return false; |
| 783 | lbm_uint shift = (pos + bitcnt) % 8; |
| 784 | lbm_uint bits = 8 - shift; |
| 785 | if (bits > remaining) bits = remaining; |
| 786 | |
| 787 | uint8_t bval, mask; |
| 788 | if (be) { |
| 789 | bval = (uint8_t)((number >> (64 - bits)) << (8 - bits - shift)); |
| 790 | mask = (uint8_t)(~(0xFFu << (8 - bits - shift)) | (0xFFu << (8 - shift))); |
| 791 | number <<= bits; |
| 792 | } else { |
| 793 | bval = (uint8_t)(number << shift); |
| 794 | mask = (uint8_t)(~(0xFFu >> (8 - bits - shift)) | (0xFFu >> (8 - shift))); |
| 795 | number >>= bits; |
| 796 | } |
| 797 | data[bytepos] = (uint8_t)((data[bytepos] & mask) | bval); |
| 798 | bitcnt += bits; |
| 799 | remaining -= bits; |
| 800 | } |
| 801 | return true; |
| 802 | } |
| 803 | |
| 804 | static bool bits_extract(const uint8_t *data, lbm_uint d_size, lbm_uint pos, lbm_uint len, |
| 805 | bool be, bool dbc, uint64_t *out) { |
| 806 | if (len == 0 || len > 64) return false; |
| 807 | if (dbc && be) pos = dbc_bit_pos(pos); |
| 808 | |
| 809 | uint64_t res = 0; |
| 810 | lbm_uint bitcnt = 0, remaining = len; |
| 23 | | 'remaining' initialized to 32 | |
|
| 811 | while (remaining > 0) { |
| 24 | | Loop condition is true. Entering loop body | |
|
| 812 | lbm_uint bytepos = (pos + bitcnt) / 8; |
| 813 | if (bytepos >= d_size) return false; |
| 25 | | Assuming 'bytepos' is < 'd_size' | |
|
| |
| 814 | lbm_uint shift = (pos + bitcnt) % 8; |
| 815 | lbm_uint bits = 8 - shift; |
| 816 | if (bits > remaining) bits = remaining; |
| 27 | | Assuming 'bits' is > 'remaining' | |
|
| |
| 29 | | The value 32 is assigned to 'bits' | |
|
| 817 | |
| 818 | if (be) { |
| |
| 819 | uint8_t bval = (uint8_t)(data[bytepos] & (0xFFu >> shift)); |
| 820 | res = (res + bval) << (bits + shift); |
| 821 | } else { |
| 822 | uint8_t mask = (uint8_t)~(0xFFu << bits); |
| 31 | | The result of the left shift is undefined due to shifting by '32', which is greater or equal to the width of type 'unsigned int' |
|
| 823 | uint8_t bval = (uint8_t)((data[bytepos] >> shift) & mask); |
| 824 | res |= ((uint64_t)bval) << bitcnt; |
| 825 | } |
| 826 | bitcnt += bits; |
| 827 | remaining -= bits; |
| 828 | } |
| 829 | if (be) res >>= 8; |
| 830 | *out = res; |
| 831 | return true; |
| 832 | } |
| 833 | |
| 834 | |
| 835 | #define BITS_IMMEDIATE_SAFE (((lbm_uint)sizeof(lbm_uint) * 8) - LBM_VAL_SHIFT) |
| 836 | |
| 837 | static lbm_value array_extensions_bufset_bits_u(lbm_value *args, lbm_uint argn) { |
| 838 | lbm_value res = ENC_SYM_EERROR; |
| 839 | lbm_uint pos, len, d_size; uint8_t *data; bool be, dbc; |
| 840 | if (decode_bits_set_args(&res, args, argn, &pos, &len, &be, &dbc, &d_size, &data)) { |
| 841 | res = bits_insert(data, d_size, pos, len, be, dbc, |
| 842 | lbm_dec_as_u64(args[3])) ? ENC_SYM_TRUE : ENC_SYM_EERROR; |
| 843 | } |
| 844 | return res; |
| 845 | } |
| 846 | |
| 847 | static lbm_value array_extensions_bufset_bits_i(lbm_value *args, lbm_uint argn) { |
| 848 | lbm_value res = ENC_SYM_EERROR; |
| 849 | lbm_uint pos, len, d_size; uint8_t *data; bool be, dbc; |
| 850 | if (decode_bits_set_args(&res, args, argn, &pos, &len, &be, &dbc, &d_size, &data)) { |
| 851 | res = bits_insert(data, d_size, pos, len, be, dbc, |
| 852 | (uint64_t)lbm_dec_as_i64(args[3])) ? ENC_SYM_TRUE : ENC_SYM_EERROR; |
| 853 | } |
| 854 | return res; |
| 855 | } |
| 856 | |
| 857 | static lbm_value array_extensions_bufget_bits_u(lbm_value *args, lbm_uint argn) { |
| 858 | lbm_value res = ENC_SYM_EERROR; |
| 859 | lbm_uint pos, len, d_size; uint8_t *data; bool be, dbc; uint64_t raw; |
| 860 | if (decode_bits_get_args(&res, args, argn, &pos, &len, &be, &dbc, &d_size, &data) && |
| 861 | bits_extract(data, d_size, pos, len, be, dbc, &raw)) { |
| 862 | if (len <= BITS_IMMEDIATE_SAFE) res = lbm_enc_u((lbm_uint)raw); |
| 863 | else if (len <= 32) res = lbm_enc_u32((uint32_t)raw); |
| 864 | else res = lbm_enc_u64(raw); |
| 865 | } |
| 866 | return res; |
| 867 | } |
| 868 | |
| 869 | static lbm_value array_extensions_bufget_bits_i(lbm_value *args, lbm_uint argn) { |
| 870 | lbm_value res = ENC_SYM_EERROR; |
| 871 | lbm_uint pos, len, d_size; uint8_t *data; bool be, dbc; uint64_t raw; |
| 872 | if (decode_bits_get_args(&res, args, argn, &pos, &len, &be, &dbc, &d_size, &data) && |
| 873 | bits_extract(data, d_size, pos, len, be, dbc, &raw)) { |
| 874 | int64_t sv = sign_extend64(raw, len); |
| 875 | if (len <= BITS_IMMEDIATE_SAFE) res = lbm_enc_i((lbm_int)sv); |
| 876 | else if (len <= 32) res = lbm_enc_i32((int32_t)sv); |
| 877 | else res = lbm_enc_i64(sv); |
| 878 | } |
| 879 | return res; |
| 880 | } |
| 881 | |
| 882 | static bool decode_bits_f32_get_args(lbm_value *error, lbm_value *args, lbm_uint argn, |
| 883 | lbm_uint *pos, bool *be, bool *dbc, |
| 884 | lbm_uint *a_size, uint8_t **a_data) { |
| 885 | *error = ENC_SYM_EERROR; |
| 886 | if (argn < 2 || argn > 4) return false; |
| |
| |
| |
| 887 | lbm_array_header_t *array = lbm_dec_array_r(args[0]); |
| 888 | if (!(array && lbm_is_number(args[1]))) { |
| 5 | | Assuming 'array' is non-null | |
|
| 6 | | Assuming the condition is false | |
|
| |
| 889 | *error = ENC_SYM_TERROR; |
| 890 | return false; |
| 891 | } |
| 892 | *a_size = array->size; |
| 893 | *a_data = (uint8_t*)array->data; |
| 894 | *pos = lbm_dec_as_u32(args[1]); |
| 895 | decode_bits_flags(args, argn, 2, be, dbc); |
| 8 | | Calling 'decode_bits_flags' | |
|
| 18 | | Returning from 'decode_bits_flags' | |
|
| 896 | return true; |
| 19 | | Returning the value 1, which participates in a condition later | |
|
| 897 | } |
| 898 | |
| 899 | static bool decode_bits_f32_set_args(lbm_value *error, lbm_value *args, lbm_uint argn, |
| 900 | lbm_uint *pos, bool *be, bool *dbc, |
| 901 | lbm_uint *a_size, uint8_t **a_data) { |
| 902 | *error = ENC_SYM_EERROR; |
| 903 | if (argn < 3 || argn > 5) return false; |
| 904 | lbm_array_header_t *array = lbm_dec_array_rw(args[0]); |
| 905 | if (!(array && lbm_is_number(args[1]) && lbm_is_number(args[2]))) { |
| 906 | *error = ENC_SYM_TERROR; |
| 907 | return false; |
| 908 | } |
| 909 | *a_size = array->size; |
| 910 | *a_data = (uint8_t*)array->data; |
| 911 | *pos = lbm_dec_as_u32(args[1]); |
| 912 | decode_bits_flags(args, argn, 3, be, dbc); |
| 913 | return true; |
| 914 | } |
| 915 | |
| 916 | static lbm_value array_extensions_bufset_bits_f32(lbm_value *args, lbm_uint argn) { |
| 917 | lbm_value res = ENC_SYM_EERROR; |
| 918 | lbm_uint pos, d_size; uint8_t *data; bool be, dbc; |
| 919 | if (decode_bits_f32_set_args(&res, args, argn, &pos, &be, &dbc, &d_size, &data)) { |
| 920 | res = bits_insert(data, d_size, pos, 32, be, dbc, |
| 921 | (uint64_t)float_to_u(lbm_dec_as_float(args[2]))) ? ENC_SYM_TRUE : ENC_SYM_EERROR; |
| 922 | } |
| 923 | return res; |
| 924 | } |
| 925 | |
| 926 | static lbm_value array_extensions_bufget_bits_f32(lbm_value *args, lbm_uint argn) { |
| 927 | lbm_value res = ENC_SYM_EERROR; |
| 928 | lbm_uint pos, d_size; uint8_t *data; bool be, dbc; uint64_t raw; |
| 929 | if (decode_bits_f32_get_args(&res, args, argn, &pos, &be, &dbc, &d_size, &data) && |
| 1 | Calling 'decode_bits_f32_get_args' | |
|
| 20 | | Returning from 'decode_bits_f32_get_args' | |
|
| 930 | bits_extract(data, d_size, pos, 32, be, dbc, &raw)) { |
| 21 | | Passing the value 32 via 4th parameter 'len' | |
|
| |
| 931 | res = lbm_enc_float(u_to_float((uint32_t)raw)); |
| 932 | } |
| 933 | return res; |
| 934 | } |