  238 |                     /* Allocate space for compact data */
  239 |                     if (NULL == (mesg->storage.u.compact.buf = H5MM_malloc(mesg->storage.u.compact.size)))
  240 |                         HGOTO_ERROR(H5E_OHDR, H5E_CANTALLOC, NULL,
  241 |                                     "memory allocation failed for compact data buffer");
  242 |
  243 |                     /* Compact data */
  244 |                     H5MM_memcpy(mesg->storage.u.compact.buf, p, mesg->storage.u.compact.size);
  245 |                     p += mesg->storage.u.compact.size;
  246 |                 }
  247 |
  248 |                 /* Set the layout operations */
  249 |                 mesg->ops = H5D_LOPS_COMPACT;
  250 |                 break;
  251 |
  252 |             case H5D_CONTIGUOUS:
  253 |                 /* Contiguous storage address */
  254 |                 if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_addr(f), p_end))
  255 |                     HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
  256 |                 H5F_addr_decode(f, &p, &(mesg->storage.u.contig.addr));
  257 |
  258 |                 /* Contiguous storage size */
  259 |                 if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_size(f), p_end))
  260 |                     HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
  261 |                 H5F_DECODE_LENGTH(f, p, mesg->storage.u.contig.size);
  262 |
  263 |                 /* Set the layout operations */
  264 |                 mesg->ops = H5D_LOPS_CONTIG;
  265 |                 break;
  266 |
  267 |             case H5D_CHUNKED:
  268 |                 if (mesg->version < H5O_LAYOUT_VERSION_4) {
  269 |                     /* Set the chunked layout flags */
  270 |                     mesg->u.chunk.flags = (uint8_t)0;
  271 |
  272 |                     /* Dimensionality */
  273 |                     if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  274 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  275 |                                     "ran off end of input buffer while decoding");
  276 |                     mesg->u.chunk.ndims = *p++;
  277 |
  278 |                     if (mesg->u.chunk.ndims > H5O_LAYOUT_NDIMS)
  279 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "dimensionality is too large");
  280 |                     if (mesg->u.chunk.ndims < 2)
  281 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "bad dimensions for chunked storage");
  282 |
  283 |                     /* B-tree address */
  284 |                     if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_addr(f), p_end))
  285 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  286 |                                     "ran off end of input buffer while decoding");
  287 |                     H5F_addr_decode(f, &p, &(mesg->storage.u.chunk.idx_addr));
  288 |
  289 |                     if (H5_IS_BUFFER_OVERFLOW(p, (mesg->u.chunk.ndims * 4), p_end))
  290 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  291 |                                     "ran off end of input buffer while decoding");
  292 |
  293 |                     /* Chunk dimensions */
  294 |                     for (unsigned u = 0; u < mesg->u.chunk.ndims; u++) {
  295 |
  296 |                         UINT32DECODE(p, mesg->u.chunk.dim[u]);
  297 |
  298 |                         /* Just in case that something goes very wrong, such as file corruption. */
  299 |                         if (mesg->u.chunk.dim[u] == 0)
  300 |                             HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  301 |                                         "bad chunk dimension value when parsing layout message - chunk "
  302 |                                         "dimension must be positive: mesg->u.chunk.dim[%u] = %" PRIuHSIZE,
  303 |                                         u, mesg->u.chunk.dim[u]);
  304 |                     }
  305 |
  306 |                     /* Compute chunk size */
  307 |                     mesg->u.chunk.size = mesg->u.chunk.dim[0];
  308 |                     for (unsigned u = 1; u < mesg->u.chunk.ndims; u++)
  309 |                         mesg->u.chunk.size *= mesg->u.chunk.dim[u];
  310 |
  311 |                     /* Set the chunk operations
  312 |                      * (Only "btree" indexing type supported with v3 of message format)
  313 |                      */
  314 |                     mesg->storage.u.chunk.idx_type = H5D_CHUNK_IDX_BTREE;
  315 |                     mesg->storage.u.chunk.ops      = H5D_COPS_BTREE;
  316 |                 }
  317 |                 else {
  318 |                     /* Get the chunked layout flags */
  319 |                     if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  320 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  321 |                                     "ran off end of input buffer while decoding");
  322 |                     mesg->u.chunk.flags = *p++;
  323 |
  324 |                     /* Check for valid flags */
  325 |                     /* (Currently issues an error for all non-zero values,
  326 |                      *      until features are added for the flags)
  327 |                      */
  328 |                     if (mesg->u.chunk.flags & ~H5O_LAYOUT_ALL_CHUNK_FLAGS)
  329 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "bad flag value for message");
  330 |
  331 |                     /* Dimensionality */
  332 |                     if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  333 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  334 |                                     "ran off end of input buffer while decoding");
  335 |                     mesg->u.chunk.ndims = *p++;
  336 |
  337 |                     if (mesg->u.chunk.ndims > H5O_LAYOUT_NDIMS)
> 338 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "dimensionality is too large");
  339 |
  340 |                     /* Encoded # of bytes for each chunk dimension */
  341 |                     if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  342 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  343 |                                     "ran off end of input buffer while decoding");
  344 |                     mesg->u.chunk.enc_bytes_per_dim = *p++;
  345 |
  346 |                     if (mesg->u.chunk.enc_bytes_per_dim == 0 || mesg->u.chunk.enc_bytes_per_dim > 8)
  347 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  348 |                                     "encoded chunk dimension size is too large");
  349 |
  350 |                     if (H5_IS_BUFFER_OVERFLOW(p, (mesg->u.chunk.ndims * mesg->u.chunk.enc_bytes_per_dim),
  351 |                                               p_end))
  352 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  353 |                                     "ran off end of input buffer while decoding");
  354 |
  355 |                     /* Chunk dimensions */
  356 |                     for (unsigned u = 0; u < mesg->u.chunk.ndims; u++) {
  357 |                         UINT64DECODE_VAR(p, mesg->u.chunk.dim[u], mesg->u.chunk.enc_bytes_per_dim);
  358 |
  359 |                         /* Just in case that something goes very wrong, such as file corruption. */
  360 |                         if (mesg->u.chunk.dim[u] == 0)
  361 |                             HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  362 |                                         "bad chunk dimension value when parsing layout message - chunk "
  363 |                                         "dimension must be positive: mesg->u.chunk.dim[%u] = %" PRIuHSIZE,
  364 |                                         u, mesg->u.chunk.dim[u]);
  365 |                     }
  366 |
  367 |                     /* Compute chunk size */
  368 |                     mesg->u.chunk.size = mesg->u.chunk.dim[0];
  369 |                     for (unsigned u = 1; u < mesg->u.chunk.ndims; u++)
  370 |                         mesg->u.chunk.size *= mesg->u.chunk.dim[u];
  371 |
  372 |                     /* Chunk index type */
  373 |                     if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  374 |                         HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  375 |                                     "ran off end of input buffer while decoding");
  376 |                     mesg->u.chunk.idx_type = (H5D_chunk_index_t)*p++;
  377 |
  378 |                     if (mesg->u.chunk.idx_type >= H5D_CHUNK_IDX_NTYPES)
  379 |                         HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "unknown chunk index type");
  380 |                     mesg->storage.u.chunk.idx_type = mesg->u.chunk.idx_type;
  381 |
  382 |                     switch (mesg->u.chunk.idx_type) {
  383 |                         case H5D_CHUNK_IDX_BTREE:
  384 |                             HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  385 |                                         "v1 B-tree index type should never be in a v4 layout message");
  386 |                             break;
  387 |
  388 |                         case H5D_CHUNK_IDX_NONE: /* Implicit Index */
  389 |                             mesg->storage.u.chunk.ops = H5D_COPS_NONE;
  390 |                             break;
  391 |
  392 |                         case H5D_CHUNK_IDX_SINGLE: /* Single Chunk Index */
  393 |                             if (mesg->u.chunk.flags & H5O_LAYOUT_CHUNK_SINGLE_INDEX_WITH_FILTER) {
  394 |                                 uint64_t nbytes = 0;
  395 |
  396 |                                 if (H5_IS_BUFFER_OVERFLOW(p, H5F_sizeof_size(f) + 4, p_end))
  397 |                                     HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  398 |                                                 "ran off end of input buffer while decoding");
  399 |
  400 |                                 H5F_DECODE_LENGTH(f, p, nbytes);
  401 |                                 H5_CHECKED_ASSIGN(mesg->storage.u.chunk.u.single.nbytes, uint32_t, nbytes,
  402 |                                                   uint64_t);
  403 |
  404 |                                 UINT32DECODE(p, mesg->storage.u.chunk.u.single.filter_mask);
  405 |                             }
  406 |
  407 |                             /* Set the chunk operations */
  408 |                             mesg->storage.u.chunk.ops = H5D_COPS_SINGLE;
  409 |                             break;
  410 |
  411 |                         case H5D_CHUNK_IDX_FARRAY:
  412 |                             /* Fixed array creation parameters */
  413 |                             if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  414 |                                 HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  415 |                                             "ran off end of input buffer while decoding");
  416 |                             mesg->u.chunk.u.farray.cparam.max_dblk_page_nelmts_bits = *p++;
  417 |
  418 |                             if (0 == mesg->u.chunk.u.farray.cparam.max_dblk_page_nelmts_bits)
  419 |                                 HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  420 |                                             "invalid fixed array creation parameter");
  421 |
  422 |                             /* Set the chunk operations */
  423 |                             mesg->storage.u.chunk.ops = H5D_COPS_FARRAY;
  424 |                             break;
  425 |
  426 |                         case H5D_CHUNK_IDX_EARRAY:
  427 |                             /* Extensible array creation parameters */
  428 |                             if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  429 |                                 HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,
  430 |                                             "ran off end of input buffer while decoding");
  431 |                             mesg->u.chunk.u.earray.cparam.max_nelmts_bits = *p++;
  432 |
  433 |                             if (0 == mesg->u.chunk.u.earray.cparam.max_nelmts_bits)
  434 |                                 HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL,
  435 |                                             "invalid extensible array creation parameter");
  436 |
  437 |                             if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
  438 |                                 HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL,

Reach line at /src/hdf5/src/H5Olayout.c:338 (observed count 1).


  7108 |     if (H5T_REFERENCE == dt->shared->type && !dt->shared->u.atomic.u.r.opaque)
  7109 |         HGOTO_DONE(true);
  7110 |
  7111 |     /* Check for types that might have the correct type as a component */
  7112 |     switch (dt->shared->type) {
  7113 |         case H5T_COMPOUND:
  7114 |             /* Iterate over all the compound datatype's fields */
  7115 |             for (u = 0; u < dt->shared->u.compnd.nmembs; u++)
  7116 |                 /* Recurse on field's datatype */
  7117 |                 if (H5T__detect_vlen_ref(dt->shared->u.compnd.memb[u].type))
  7118 |                     HGOTO_DONE(true);
  7119 |             break;
  7120 |
  7121 |         case H5T_ARRAY:
  7122 |         case H5T_VLEN:
  7123 |         case H5T_ENUM:
  7124 |             HGOTO_DONE(H5T__detect_vlen_ref(dt->shared->parent));
  7125 |             break;
  7126 |
  7127 |         case H5T_NO_CLASS:
  7128 |         case H5T_INTEGER:
  7129 |         case H5T_FLOAT:
  7130 |         case H5T_TIME:
  7131 |         case H5T_STRING:
  7132 |         case H5T_BITFIELD:
  7133 |         case H5T_OPAQUE:
  7134 |         case H5T_REFERENCE:
  7135 |         case H5T_COMPLEX:
  7136 |         case H5T_NCLASSES:
  7137 |         default:
  7138 |             break;
  7139 |     } /* end if */
  7140 |
  7141 | done:
  7142 |     FUNC_LEAVE_NOAPI(ret_value)
  7143 | } /* end H5T__detect_vlen_ref() */
  7144 |
  7145 | /*-------------------------------------------------------------------------
  7146 |  * Function:    H5T_is_vl_storage
  7147 |  *
  7148 |  * Purpose:     Check if a datatype will be stored in a variable-length form.
  7149 |  *
  7150 |  * Notes:       Currently, only variable-length string & sequences and region
  7151 |  *              references are stored in a variable-length form.
  7152 |  *
  7153 |  * Return:
  7154 |  *  One of two values on success:
  7155 |  *      true - If the datatype will be stored in a variable-length form
  7156 |  *      false - If the datatype will NOT be stored in a variable-length form
  7157 |  *  <0 is returned on failure
  7158 |  *
  7159 |  *-------------------------------------------------------------------------
  7160 |  */
  7161 | htri_t
  7162 | H5T_is_vl_storage(const H5T_t *dt)
  7163 | {
  7164 |     htri_t ret_value = false;
  7165 |
  7166 |     FUNC_ENTER_NOAPI(FAIL)
  7167 |
  7168 |     /* Sanity check */
  7169 |     assert(dt);
  7170 |
  7171 |     /* VL and region reference datatypes are stored in variable-length form */
  7172 |     if (H5T_detect_class(dt, H5T_VLEN, false))
  7173 |         ret_value = true;
  7174 |     else if (H5T_detect_class(dt, H5T_REFERENCE, false))
  7175 |         ret_value = H5T__detect_vlen_ref(dt);
  7176 |     else
  7177 |         ret_value = false;
  7178 |
  7179 | done:
  7180 |     FUNC_LEAVE_NOAPI(ret_value)
  7181 | } /* end H5T_is_vl_storage() */
  7182 |
  7183 | /*-------------------------------------------------------------------------
  7184 |  * Function:    H5T__upgrade_version_cb
  7185 |  *
  7186 |  * Purpose:     H5T__visit callback to Upgrade the version of a datatype
  7187 |  *              (if there's any benefit to doing so)
  7188 |  *
  7189 |  * Note:        The behavior below is tightly coupled with the "better"
  7190 |  *              encodings for datatype messages in the datatype message
  7191 |  *              encoding routine.
  7192 |  *
  7193 |  * Return:      Non-negative on success/Negative on failure
  7194 |  *
  7195 |  *-------------------------------------------------------------------------
  7196 |  */
  7197 | static herr_t
  7198 | H5T__upgrade_version_cb(H5T_t *dt, void *op_value)
  7199 | {
  7200 |     FUNC_ENTER_PACKAGE_NOERR
  7201 |
  7202 |     /* Sanity check */
  7203 |     assert(dt);
  7204 |     assert(op_value);
  7205 |
  7206 |     /* Special behavior for each type of datatype */
  7207 |     switch (dt->shared->type) {
> 7208 |         case H5T_COMPOUND:
  7209 |         case H5T_ARRAY:
  7210 |         case H5T_ENUM:
  7211 |             /* These types benefit from "upgrading" their version */
  7212 |             if (*(unsigned *)op_value > dt->shared->version)
  7213 |                 dt->shared->version = *(unsigned *)op_value;
  7214 |             break;
  7215 |
  7216 |         case H5T_VLEN:
  7217 |             if (dt->shared->parent->shared->version > dt->shared->version)
  7218 |                 dt->shared->version = dt->shared->parent->shared->version;
  7219 |             break;
  7220 |
  7221 |         case H5T_COMPLEX:
  7222 |             if (dt->shared->parent->shared->version > dt->shared->version)
  7223 |                 dt->shared->version = dt->shared->parent->shared->version;
  7224 |             break;
  7225 |
  7226 |         case H5T_NO_CLASS:
  7227 |         case H5T_INTEGER:
  7228 |         case H5T_FLOAT:
  7229 |         case H5T_TIME:
  7230 |         case H5T_STRING:
  7231 |         case H5T_BITFIELD:
  7232 |         case H5T_OPAQUE:
  7233 |         case H5T_REFERENCE:
  7234 |         case H5T_NCLASSES:
  7235 |         default:
  7236 |             break;
  7237 |     } /* end switch */
  7238 |
  7239 |     FUNC_LEAVE_NOAPI(SUCCEED)
  7240 | } /* end H5T__upgrade_version_cb() */
  7241 |
  7242 | /*-------------------------------------------------------------------------
  7243 |  * Function:    H5T__upgrade_version
  7244 |  *
  7245 |  * Purpose:     Upgrade the version of a datatype (if there's any benefit to
  7246 |  *              doing so) and recursively apply to compound members and/or
  7247 |  *              parent datatypes.
  7248 |  *
  7249 |  * Return:      Non-negative on success/Negative on failure
  7250 |  *
  7251 |  *-------------------------------------------------------------------------
  7252 |  */
  7253 | herr_t
  7254 | H5T__upgrade_version(H5T_t *dt, unsigned new_version)
  7255 | {
  7256 |     herr_t ret_value = SUCCEED; /* Return value */
  7257 |
  7258 |     FUNC_ENTER_PACKAGE
  7259 |
  7260 |     /* Sanity check */
  7261 |     assert(dt);
  7262 |
  7263 |     /* Iterate over entire datatype, upgrading the version of components, if it's useful */
  7264 |     if (H5T__visit(dt, (H5T_VISIT_SIMPLE | H5T_VISIT_COMPOSITE_LAST), H5T__upgrade_version_cb, &new_version) <
  7265 |         0)
  7266 |         HGOTO_ERROR(H5E_DATATYPE, H5E_BADITER, FAIL, "iteration to upgrade datatype encoding version failed");
  7267 |
  7268 | done:
  7269 |     FUNC_LEAVE_NOAPI(ret_value)
  7270 | } /* end H5T__upgrade_version() */
  7271 |
  7272 | /*-------------------------------------------------------------------------
  7273 |  * Function:    H5T_set_version
  7274 |  *
  7275 |  * Purpose:     Set the encoding for a datatype to the version indicated by
  7276 |  *              the file's low bound if that is higher than the datatype's
  7277 |  *              version.
  7278 |  *
  7279 |  * Return:      Non-negative on success/Negative on failure
  7280 |  *
  7281 |  *-------------------------------------------------------------------------
  7282 |  */
  7283 | herr_t
  7284 | H5T_set_version(H5F_t *f, H5T_t *dt)
  7285 | {
  7286 |     unsigned vers;                /* The version */
  7287 |     herr_t   ret_value = SUCCEED; /* Return value */
  7288 |
  7289 |     FUNC_ENTER_NOAPI(FAIL)
  7290 |
  7291 |     /* Sanity check */
  7292 |     assert(f);
  7293 |     assert(dt);
  7294 |
  7295 |     vers = H5O_dtype_ver_bounds[H5F_LOW_BOUND(f)];
  7296 |     if (vers > dt->shared->version) {
  7297 |         /* Upgrade the format version for the datatype */
  7298 |         if (H5T__upgrade_version(dt, vers) < 0)
  7299 |             HGOTO_ERROR(H5E_DATATYPE, H5E_CANTSET, FAIL, "can't upgrade datatype encoding");
  7300 |     }
  7301 |
  7302 |     /* Version bounds check */
  7303 |     if (dt->shared->version > H5O_dtype_ver_bounds[H5F_HIGH_BOUND(f)])
  7304 |         HGOTO_ERROR(H5E_DATATYPE, H5E_BADRANGE, FAIL, "Datatype version out of bounds");
  7305 |
  7306 | done:
  7307 |     FUNC_LEAVE_NOAPI(ret_value)
  7308 | } /* end H5T_set_version() */

Reach line at /src/hdf5/src/H5T.c:7208 (observed count 292).


  581 |      * Tell the file driver how much address space has already been
  582 |      * allocated so that it knows how to allocate additional memory.
  583 |      */
  584 |
  585 |     /* Set the ring type in the API context */
  586 |     H5AC_set_ring(H5AC_RING_SBE, NULL);
  587 |
  588 |     /* Decode the optional driver information block */
  589 |     if (H5_addr_defined(sblock->driver_addr)) {
  590 |         H5O_drvinfo_t          *drvinfo;             /* Driver info */
  591 |         H5F_drvrinfo_cache_ud_t drvrinfo_udata;      /* User data for metadata callbacks */
  592 |         unsigned drvinfo_flags = H5AC__NO_FLAGS_SET; /* Flags used in driver info block unprotect call */
  593 |
  594 |         /* Sanity check - driver info block should only be defined for
  595 |          *      superblock version < 2.
  596 |          */
  597 |         assert(sblock->super_vers < HDF5_SUPERBLOCK_VERSION_2);
  598 |
  599 |         /* Set up user data */
  600 |         drvrinfo_udata.f           = f;
  601 |         drvrinfo_udata.driver_addr = sblock->driver_addr;
  602 |
  603 |         /* extend EOA so we can read at least the fixed sized
  604 |          * portion of the driver info block
  605 |          */
  606 |         if (H5FD_set_eoa(f->shared->lf, H5FD_MEM_SUPER, sblock->driver_addr + H5F_DRVINFOBLOCK_HDR_SIZE) <
  607 |             0) /* will extend eoa later if required */
  608 |             HGOTO_ERROR(H5E_FILE, H5E_CANTINIT, FAIL, "set end of space allocation request failed");
  609 |
  610 |         /* Look up the driver info block */
  611 |         if (NULL == (drvinfo = (H5O_drvinfo_t *)H5AC_protect(f, H5AC_DRVRINFO, sblock->driver_addr,
  612 |                                                              &drvrinfo_udata, rw_flags)))
  613 |             HGOTO_ERROR(H5E_FILE, H5E_CANTPROTECT, FAIL, "unable to load driver info block");
  614 |
  615 |         /* Loading the driver info block is enough to set up the right info */
  616 |
  617 |         /* Check if we need to rewrite the driver info block info */
  618 |         if (((rw_flags & H5AC__READ_ONLY_FLAG) == 0) && H5F_HAS_FEATURE(f, H5FD_FEAT_DIRTY_DRVRINFO_LOAD))
  619 |             drvinfo_flags |= H5AC__DIRTIED_FLAG;
  620 |
  621 |         /* set the pin entry flag so that the driver information block
  622 |          * cache entry will be pinned in the cache.
  623 |          */
  624 |         drvinfo_flags |= H5AC__PIN_ENTRY_FLAG;
  625 |
  626 |         /* Release the driver info block */
  627 |         if (H5AC_unprotect(f, H5AC_DRVRINFO, sblock->driver_addr, drvinfo, drvinfo_flags) < 0)
  628 |             HGOTO_ERROR(H5E_FILE, H5E_CANTUNPROTECT, FAIL, "unable to release driver info block");
  629 |
  630 |         /* save a pointer to the driver information cache entry */
  631 |         f->shared->drvinfo = drvinfo;
  632 |     } /* end if */
  633 |
  634 |     /* (Account for the stored EOA being absolute offset -NAF) */
  635 |     if (H5F__set_eoa(f, H5FD_MEM_DEFAULT, udata.stored_eof - sblock->base_addr) < 0)
  636 |         HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set end-of-address marker for file");
  637 |
  638 |     /* Decode the optional superblock extension info */
  639 |     if (H5_addr_defined(sblock->ext_addr)) {
  640 |         H5O_loc_t     ext_loc; /* "Object location" for superblock extension */
  641 |         H5O_btreek_t  btreek;  /* v1 B-tree 'K' value message from superblock extension */
  642 |         H5O_drvinfo_t drvinfo; /* Driver info message from superblock extension */
  643 |         size_t        u;       /* Local index variable */
  644 |         htri_t        status;  /* Status for message existing */
  645 |
  646 |         /* Sanity check - superblock extension should only be defined for
  647 |          *      superblock version >= 2.
  648 |          */
  649 |         if (sblock->super_vers < HDF5_SUPERBLOCK_VERSION_2)
  650 |             HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
  651 |                         "invalid superblock - extension message should not be defined for version < 2");
  652 |
  653 |         /* Check for superblock extension being located "outside" the stored
  654 |          *      'eoa' value, which can occur with the split/multi VFD.
  655 |          */
  656 |         if (H5_addr_gt(sblock->ext_addr, udata.stored_eof)) {
  657 |             /* Set the 'eoa' for the object header memory type large enough
  658 |              *  to give some room for a reasonably sized superblock extension.
  659 |              *  (This is _rather_ a kludge -QAK)
  660 |              */
  661 |             if (H5F__set_eoa(f, H5FD_MEM_OHDR, (haddr_t)(sblock->ext_addr + 1024)) < 0)
  662 |                 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set end-of-address marker for file");
  663 |         } /* end if */
  664 |
  665 |         /* Open the superblock extension */
  666 |         if (H5F__super_ext_open(f, sblock->ext_addr, &ext_loc) < 0)
  667 |             HGOTO_ERROR(H5E_FILE, H5E_CANTOPENOBJ, FAIL, "unable to open file's superblock extension");
  668 |
  669 |         /* Check for the extension having a 'driver info' message */
  670 |         if ((status = H5O_msg_exists(&ext_loc, H5O_DRVINFO_ID)) < 0)
  671 |             HGOTO_ERROR(H5E_FILE, H5E_EXISTS, FAIL, "unable to read object header");
  672 |         if (status) {
  673 |             /* Check for ignoring the driver info for this file */
  674 |             if (!udata.ignore_drvrinfo) {
  675 |
  676 |                 /* Retrieve the 'driver info' structure */
  677 |                 if (NULL == H5O_msg_read(&ext_loc, H5O_DRVINFO_ID, &drvinfo))
  678 |                     HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "driver info message not present");
  679 |
  680 |                 /* Validate and decode driver information */
> 681 |                 if (H5FD_sb_load(f->shared->lf, drvinfo.name, drvinfo.buf) < 0) {
  682 |                     H5O_msg_reset(H5O_DRVINFO_ID, &drvinfo);
  683 |                     HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "unable to decode driver information");
  684 |                 } /* end if */
  685 |
  686 |                 /* Reset driver info message */
  687 |                 H5O_msg_reset(H5O_DRVINFO_ID, &drvinfo);
  688 |
  689 |                 assert(false == f->shared->drvinfo_sb_msg_exists);
  690 |                 f->shared->drvinfo_sb_msg_exists = true;
  691 |             } /* end else */
  692 |         }     /* end if */
  693 |
  694 |         /* Read in the shared OH message information if there is any */
  695 |         if (H5SM_get_info(&ext_loc, c_plist) < 0)
  696 |             HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to read SOHM table information");
  697 |
  698 |         /* Check for the extension having a 'v1 B-tree "K"' message */
  699 |         if ((status = H5O_msg_exists(&ext_loc, H5O_BTREEK_ID)) < 0)
  700 |             HGOTO_ERROR(H5E_FILE, H5E_EXISTS, FAIL, "unable to read object header");
  701 |         if (status) {
  702 |             /* Retrieve the 'v1 B-tree "K"' structure */
  703 |             if (NULL == H5O_msg_read(&ext_loc, H5O_BTREEK_ID, &btreek))
  704 |                 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "v1 B-tree 'K' info message not present");
  705 |
  706 |             /* Set non-default v1 B-tree 'K' value info from file */
  707 |             sblock->btree_k[H5B_CHUNK_ID] = btreek.btree_k[H5B_CHUNK_ID];
  708 |             sblock->btree_k[H5B_SNODE_ID] = btreek.btree_k[H5B_SNODE_ID];
  709 |             sblock->sym_leaf_k            = btreek.sym_leaf_k;
  710 |
  711 |             /* Set non-default v1 B-tree 'K' values in the property list */
  712 |             if (H5P_set(c_plist, H5F_CRT_BTREE_RANK_NAME, btreek.btree_k) < 0)
  713 |                 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set rank for btree internal nodes");
  714 |             if (H5P_set(c_plist, H5F_CRT_SYM_LEAF_NAME, &btreek.sym_leaf_k) < 0)
  715 |                 HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set rank for symbol table leaf nodes");
  716 |         } /* end if */
  717 |
  718 |         /* Check for the extension having a 'free-space manager info' message */
  719 |         if ((status = H5O_msg_exists(&ext_loc, H5O_FSINFO_ID)) < 0)
  720 |             HGOTO_ERROR(H5E_FILE, H5E_EXISTS, FAIL, "unable to read object header");
  721 |         if (status) {
  722 |             uint8_t flags; /* Message flags */
  723 |
  724 |             /* Get message flags */
  725 |             if (H5O_msg_get_flags(&ext_loc, H5O_FSINFO_ID, &flags) < 0)
  726 |                 HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL,
  727 |                             "unable to message flags for free-space manager info message");
  728 |
  729 |             /* If message is NOT marked "unknown"--set up file space info  */
  730 |             if (!(flags & H5O_MSG_FLAG_WAS_UNKNOWN)) {
  731 |                 H5O_fsinfo_t fsinfo; /* File space info message from superblock extension */
  732 |
  733 |                 memset(&fsinfo, 0, sizeof(H5O_fsinfo_t));
  734 |
  735 |                 /* f->shared->null_fsm_addr: Whether to drop free-space to the floor */
  736 |                 /* The h5clear tool uses this property to tell the library
  737 |                  * to drop free-space to the floor
  738 |                  */
  739 |                 if (H5P_exist_plist(fa_plist, H5F_ACS_NULL_FSM_ADDR_NAME) > 0)
  740 |                     if (H5P_get(fa_plist, H5F_ACS_NULL_FSM_ADDR_NAME, &f->shared->null_fsm_addr) < 0)
  741 |                         HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL,
  742 |                                     "can't get clearance for persisting fsm addr");
  743 |
  744 |                 /* Retrieve the 'file space info' structure */
  745 |                 if (NULL == H5O_msg_read(&ext_loc, H5O_FSINFO_ID, &fsinfo))
  746 |                     HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to get free-space manager info message");
  747 |
  748 |                 /* Version bounds check */
  749 |                 if (H5O_fsinfo_check_version(H5F_HIGH_BOUND(f), &fsinfo) < 0)
  750 |                     HGOTO_ERROR(H5E_FILE, H5E_BADRANGE, FAIL,
  751 |                                 "File space info message's version out of bounds");
  752 |
  753 |                 /* Update changed values */
  754 |                 if (f->shared->fs_version != fsinfo.version)
  755 |                     f->shared->fs_version = fsinfo.version;
  756 |                 if (f->shared->fs_strategy != fsinfo.strategy) {
  757 |                     f->shared->fs_strategy = fsinfo.strategy;
  758 |
  759 |                     /* Set non-default strategy in the property list */
  760 |                     if (H5P_set(c_plist, H5F_CRT_FILE_SPACE_STRATEGY_NAME, &fsinfo.strategy) < 0)
  761 |                         HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set file space strategy");
  762 |                 } /* end if */
  763 |                 if (f->shared->fs_persist != fsinfo.persist) {
  764 |                     f->shared->fs_persist = fsinfo.persist;
  765 |
  766 |                     /* Set non-default strategy in the property list */
  767 |                     if (H5P_set(c_plist, H5F_CRT_FREE_SPACE_PERSIST_NAME, &fsinfo.persist) < 0)
  768 |                         HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set file space strategy");
  769 |                 } /* end if */
  770 |                 if (f->shared->fs_threshold != fsinfo.threshold) {
  771 |                     f->shared->fs_threshold = fsinfo.threshold;
  772 |
  773 |                     /* Set non-default threshold in the property list */
  774 |                     if (H5P_set(c_plist, H5F_CRT_FREE_SPACE_THRESHOLD_NAME, &fsinfo.threshold) < 0)
  775 |                         HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "unable to set file space strategy");
  776 |                 } /* end if */
  777 |
  778 |                 if (f->shared->fs_page_size < H5F_FILE_SPACE_PAGE_SIZE_MIN)
  779 |                     HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file space page size too small");
  780 |                 if (fsinfo.page_size < H5F_FILE_SPACE_PAGE_SIZE_MIN)
  781 |                     HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "file space page size too small");

Reach line at /src/hdf5/src/H5Fsuper.c:681 (observed count 1).


  426 |     // hash twice 16 bytes, running 2 scramble rounds of AES on itself
  427 |     template <ZeroExtension ZX>
  428 |     static void QT_FUNCTION_TARGET(AES) QT_VECTORCALL
  429 |     hash2x16bytes(__m128i &state0, __m128i &state1, const __m128i *src0, const __m128i *src1)
  430 |     {
  431 |         __m128i data0 = loadu128<ZX>(src0);
  432 |         __m128i data1 = loadu128<ZX>(src1);
  433 |         state0 = _mm_xor_si128(data0, state0);
  434 |         state1 = _mm_xor_si128(data1, state1);
  435 |         state0 = _mm_aesenc_si128(state0, state0);
  436 |         state1 = _mm_aesenc_si128(state1, state1);
  437 |         state0 = _mm_aesenc_si128(state0, state0);
  438 |         state1 = _mm_aesenc_si128(state1, state1);
  439 |     }
  440 |
  441 |     struct AESHashSeed
  442 |     {
  443 |         __m128i state0;
  444 |         __m128i mseed2;
  445 |         AESHashSeed(size_t seed, size_t seed2) QT_FUNCTION_TARGET(AES);
  446 |         __m128i state1() const QT_FUNCTION_TARGET(AES);
  447 |         __m256i state0_256() const QT_FUNCTION_TARGET(AES_AVX2)
  448 |         { return _mm256_set_m128i(state1(), state0); }
  449 |     };
  450 | } // unnamed namespace
  451 |
  452 | Q_ALWAYS_INLINE AESHashSeed::AESHashSeed(size_t seed, size_t seed2)
  453 | {
  454 |     __m128i mseed = mm_cvtsz_si128(seed);
  455 |     mseed2 = mm_set1_epz(seed2);
  456 |
  457 |     // mseed (epi16) = [ seed, seed >> 16, seed >> 32, seed >> 48, len, 0, 0, 0 ]
  458 |     mseed = _mm_insert_epi16(mseed, short(seed), 4);
  459 |     // mseed (epi16) = [ seed, seed >> 16, seed >> 32, seed >> 48, len, len, len, len ]
  460 |     mseed = _mm_shufflehi_epi16(mseed, 0);
  461 |
  462 |     // merge with the process-global seed
  463 |     __m128i key = _mm_xor_si128(mseed, mseed2);
  464 |
  465 |     // scramble the key
  466 |     __m128i state0 = _mm_aesenc_si128(key, key);
  467 |     this->state0 = state0;
  468 | }
  469 |
  470 | Q_ALWAYS_INLINE __m128i AESHashSeed::state1() const
  471 | {
  472 |     {
  473 |         // unlike the Go code, we don't have more per-process seed
  474 |         __m128i state1 = _mm_aesenc_si128(state0, mseed2);
  475 |         return state1;
  476 |     }
  477 | }
  478 |
  479 | template <ZeroExtension ZX>
  480 | static size_t QT_FUNCTION_TARGET(AES) QT_VECTORCALL
  481 | aeshash128_16to32(__m128i state0, __m128i state1, const __m128i *src, const __m128i *srcend)
  482 | {
  483 |     {
  484 |         const __m128i *src2 = advance<ZX>(srcend, -1);
  485 |         if (advance<ZX>(src, 1) < srcend) {
  486 |             // epilogue: between 16 and 31 bytes
  487 |             hash2x16bytes<ZX>(state0, state1, src, src2);
  488 |         } else if (src != srcend) {
  489 |             // epilogue: between 1 and 16 bytes, overlap with the end
  490 |             __m128i data = loadu128<ZX>(src2);
  491 |             hash16bytes(state0, data);
  492 |         }
  493 |
  494 |         // combine results:
  495 |         state0 = _mm_xor_si128(state0, state1);
  496 |     }
  497 |
  498 |     return mm_cvtsi128_sz(state0);
  499 | }
  500 |
  501 | // load all 16 bytes and mask off the bytes past the end of the source
  502 | static const qint8 maskarray[] = {
  503 |     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  504 |     0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
  505 | };
  506 |
  507 | // load 16 bytes ending at the data end, then shuffle them to the beginning
  508 | static const qint8 shufflecontrol[] = {
  509 |     1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  510 |     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
  511 | };
  512 |
  513 | template <ZeroExtension ZX>
  514 | static size_t QT_FUNCTION_TARGET(AES) QT_VECTORCALL
  515 | aeshash128_lt16(__m128i state0, const __m128i *src, const __m128i *srcend, size_t len)
  516 | {
  517 |     if (len) {
  518 |         // We're going to load 16 bytes and mask zero the part we don't care
  519 |         // (the hash of a short string is different from the hash of a longer
  520 |         // including NULLs at the end because the length is in the key)
  521 |         // WARNING: this may produce valgrind warnings, but it's safe
  522 |
  523 |         constexpr quintptr CachelineSize = 64;
  524 |         __m128i data;
  525 |
> 526 |         if ((quintptr(src) & (CachelineSize / 2)) == 0) {
  527 |             // lower half of the cacheline:
  528 |             __m128i mask = _mm_loadu_si128(reinterpret_cast<const __m128i *>(maskarray + 15 - len));
  529 |             data = loadu128<ZX>(src);
  530 |             data = _mm_and_si128(data, mask);
  531 |         } else {
  532 |             // upper half of the cacheline:
  533 |             __m128i control = _mm_loadu_si128(reinterpret_cast<const __m128i *>(shufflecontrol + 15 - len));
  534 |             data = loadu128<ZX>(advance<ZX>(srcend, -1));
  535 |             data = _mm_shuffle_epi8(data, control);
  536 |         }
  537 |
  538 |         hash16bytes(state0, data);
  539 |     }
  540 |     return mm_cvtsi128_sz(state0);
  541 | }
  542 |
  543 | template <ZeroExtension ZX>
  544 | static size_t QT_FUNCTION_TARGET(AES) QT_VECTORCALL
  545 | aeshash128_ge32(__m128i state0, __m128i state1, const __m128i *src, const __m128i *srcend)
  546 | {
  547 |     // main loop: scramble two 16-byte blocks
  548 |     for ( ; advance<ZX>(src, 2) < srcend; src = advance<ZX>(src, 2))
  549 |         hash2x16bytes<ZX>(state0, state1, src, advance<ZX>(src, 1));
  550 |
  551 |     return aeshash128_16to32<ZX>(state0, state1, src, srcend);
  552 | }
  553 |
  554 | #  if QT_COMPILER_SUPPORTS_HERE(VAES)
  555 | template <ZeroExtension> static __m256i loadu256(const void *ptr);
  556 | template <> Q_ALWAYS_INLINE QT_FUNCTION_TARGET(VAES) __m256i loadu256<None>(const void *ptr)
  557 | {
  558 |     return _mm256_loadu_si256(reinterpret_cast<const __m256i *>(ptr));
  559 | }
  560 | template <> Q_ALWAYS_INLINE QT_FUNCTION_TARGET(VAES) __m256i loadu256<ByteToWord>(const void *ptr)
  561 | {
  562 |     // VPMOVZXBW xmm, ymm
  563 |     __m128i data = _mm_loadu_si128(reinterpret_cast<const __m128i *>(ptr));
  564 |     return _mm256_cvtepu8_epi16(data);
  565 | }
  566 |
  567 | template <ZeroExtension ZX>
  568 | static size_t QT_FUNCTION_TARGET(VAES_AVX512) QT_VECTORCALL
  569 | aeshash256_lt32_avx256(__m256i state0, const uchar *p, size_t len)
  570 | {
  571 |     __m128i state0_128 = _mm256_castsi256_si128(state0);
  572 |     if (len) {
  573 |         __m256i data;
  574 |         if constexpr (ZX == None) {
  575 |             __mmask32 mask = _bzhi_u32(-1, unsigned(len));
  576 |             data = _mm256_maskz_loadu_epi8(mask, p);
  577 |         } else {
  578 |             __mmask16 mask = _bzhi_u32(-1, unsigned(len) / 2);
  579 |             __m128i data0 = _mm_maskz_loadu_epi8(mask, p);
  580 |             data = _mm256_cvtepu8_epi16(data0);
  581 |         }
  582 |         __m128i data0 = _mm256_castsi256_si128(data);
  583 |         if (len >= sizeof(__m128i)) {
  584 |             state0 = _mm256_xor_si256(state0, data);
  585 |             state0 = _mm256_aesenc_epi128(state0, state0);
  586 |             state0 = _mm256_aesenc_epi128(state0, state0);
  587 |             // we're XOR'ing the two halves so we skip the third AESENC
  588 |             // state0 = _mm256_aesenc_epi128(state0, state0);
  589 |
  590 |             // XOR the two halves and extract
  591 |             __m128i low = _mm256_extracti128_si256(state0, 0);
  592 |             __m128i high = _mm256_extracti128_si256(state0, 1);
  593 |             state0_128 = _mm_xor_si128(low, high);
  594 |         } else {
  595 |             hash16bytes(state0_128, data0);
  596 |         }
  597 |     }
  598 |     return mm_cvtsi128_sz(state0_128);
  599 | }
  600 |
  601 | template <ZeroExtension ZX>
  602 | static size_t QT_FUNCTION_TARGET(VAES) QT_VECTORCALL
  603 | aeshash256_ge32(__m256i state0, const __m128i *s, const __m128i *end, size_t len)
  604 | {
  605 |     static const auto hash32bytes = [](__m256i &state0, __m256i data) QT_FUNCTION_TARGET(VAES) {
  606 |         state0 = _mm256_xor_si256(state0, data);
  607 |         state0 = _mm256_aesenc_epi128(state0, state0);
  608 |         state0 = _mm256_aesenc_epi128(state0, state0);
  609 |         state0 = _mm256_aesenc_epi128(state0, state0);
  610 |     };
  611 |
  612 |     // hash twice 32 bytes, running 2 scramble rounds of AES on itself
  613 |     const auto hash2x32bytes = [](__m256i &state0, __m256i &state1, const void *src0,
  614 |             const void *src1) QT_FUNCTION_TARGET(VAES) {
  615 |         __m256i data0 = loadu256<ZX>(src0);
  616 |         __m256i data1 = loadu256<ZX>(src1);
  617 |         state0 = _mm256_xor_si256(data0, state0);
  618 |         state1 = _mm256_xor_si256(data1, state1);
  619 |         state0 = _mm256_aesenc_epi128(state0, state0);
  620 |         state1 = _mm256_aesenc_epi128(state1, state1);
  621 |         state0 = _mm256_aesenc_epi128(state0, state0);
  622 |         state1 = _mm256_aesenc_epi128(state1, state1);
  623 |     };
  624 |
  625 |     const __m256i *src = reinterpret_cast<const __m256i *>(s);
  626 |     const __m256i *srcend = reinterpret_cast<const __m256i *>(end);

Reach line at /src/qtbase/src/corelib/tools/qhash.cpp:526 (observed count 7600000).


  314 | 	}
  315 | 	const size_t offset = alignment - 1 + sizeof(uint8_t);
  316 | 	uint8_t *buffer = OSSL_FUNC(CRYPTO_malloc)(size + offset, OPENSSL_FILE, OPENSSL_LINE);
  317 | 	if (!buffer) {
  318 | 		return NULL;
  319 | 	}
  320 | 	uint8_t *ptr = (uint8_t *)(((uintptr_t)(buffer) + offset) & ~(alignment - 1));
  321 | 	ptrdiff_t diff = ptr - buffer;
  322 | 	if (diff > UINT8_MAX) {
  323 | 		// Free and return NULL if alignment is too large
  324 | 		OSSL_FUNC(CRYPTO_free)(buffer, OPENSSL_FILE, OPENSSL_LINE);
  325 | 		errno = EINVAL;
  326 | 		return NULL;
  327 | 	}
  328 | 	// Store the difference so that the free function can use it
  329 | 	ptr[-1] = (uint8_t)diff;
  330 | 	return ptr;
  331 | #elif defined(OQS_HAVE_ALIGNED_ALLOC) // glibc and other implementations providing aligned_alloc
  332 | 	return aligned_alloc(alignment, size);
  333 | #else
  334 | 	// Check alignment (power of 2, and >= sizeof(void*)) and size (multiple of alignment)
  335 | 	if (alignment & (alignment - 1) || size & (alignment - 1) || alignment < sizeof(void *)) {
  336 | 		errno = EINVAL;
  337 | 		return NULL;
  338 | 	}
  339 |
  340 | #if defined(OQS_HAVE_POSIX_MEMALIGN)
  341 | 	void *ptr = NULL;
  342 | 	const int err = posix_memalign(&ptr, alignment, size);
  343 | 	if (err) {
  344 | 		errno = err;
  345 | 		ptr = NULL;
  346 | 	}
  347 | 	return ptr;
  348 | #elif defined(OQS_HAVE_MEMALIGN)
  349 | 	return memalign(alignment, size);
  350 | #elif defined(__MINGW32__) || defined(__MINGW64__)
  351 | 	return __mingw_aligned_malloc(size, alignment);
  352 | #elif defined(_MSC_VER)
  353 | 	return _aligned_malloc(size, alignment);
  354 | #else
  355 | 	if (!size) {
  356 | 		return NULL;
  357 | 	}
  358 | 	// Overallocate to be able to align the pointer (alignment -1) and to store
  359 | 	// the difference between the pointer returned to the user (ptr) and the
  360 | 	// pointer returned by malloc (buffer). The difference is caped to 255 and
  361 | 	// can be made larger if necessary, but this should be enough for all users
  362 | 	// in liboqs.
  363 | 	//
  364 | 	// buffer      ptr
  365 | 	// ↓           ↓
  366 | 	// ...........|...................
  367 | 	//            |
  368 | 	//       diff = ptr - buffer
  369 | 	const size_t offset = alignment - 1 + sizeof(uint8_t);
  370 | 	uint8_t *buffer = malloc(size + offset); // IGNORE memory-check
  371 | 	if (!buffer) {
  372 | 		return NULL;
  373 | 	}
  374 |
  375 | 	// Align the pointer returned to the user.
  376 | 	uint8_t *ptr = (uint8_t *)(((uintptr_t)(buffer) + offset) & ~(alignment - 1));
  377 | 	ptrdiff_t diff = ptr - buffer;
  378 | 	if (diff > UINT8_MAX) {
  379 | 		// This should never happen in our code, but just to be safe
  380 | 		free(buffer); // IGNORE memory-check
  381 | 		errno = EINVAL;
  382 | 		return NULL;
  383 | 	}
  384 | 	// Store the difference one byte ahead the returned poitner so that free
  385 | 	// can reconstruct buffer.
  386 | 	ptr[-1] = diff;
  387 | 	return ptr;
  388 | #endif
  389 | #endif
  390 | }
  391 |
  392 | void OQS_MEM_aligned_free(void *ptr) {
  393 | 	if (ptr == NULL) {
  394 | 		return;
  395 | 	}
  396 | #if defined(OQS_USE_OPENSSL)
  397 | 	// Use OpenSSL's free function
  398 | 	uint8_t *u8ptr = ptr;
  399 | 	OSSL_FUNC(CRYPTO_free)(u8ptr - u8ptr[-1], OPENSSL_FILE, OPENSSL_LINE);
  400 | #elif defined(OQS_HAVE_ALIGNED_ALLOC) || defined(OQS_HAVE_POSIX_MEMALIGN) || defined(OQS_HAVE_MEMALIGN)
  401 | 	free(ptr); // IGNORE memory-check
  402 | #elif defined(__MINGW32__) || defined(__MINGW64__)
  403 | 	__mingw_aligned_free(ptr);
  404 | #elif defined(_MSC_VER)
  405 | 	_aligned_free(ptr);
  406 | #else
  407 | 	// Reconstruct the pointer returned from malloc using the difference
  408 | 	// stored one byte ahead of ptr.
  409 | 	uint8_t *u8ptr = ptr;
  410 | 	free(u8ptr - u8ptr[-1]); // IGNORE memory-check
  411 | #endif
  412 | }
  413 |
> 414 | void OQS_MEM_aligned_secure_free(void *ptr, size_t len) {
  415 | 	OQS_MEM_cleanse(ptr, len);
  416 | 	OQS_MEM_aligned_free(ptr);
  417 | }
  418 |
  419 | OQS_API void *OQS_MEM_malloc(size_t size) {
  420 | #if defined(OQS_USE_OPENSSL)
  421 | 	return OSSL_FUNC(CRYPTO_malloc)(size, OPENSSL_FILE, OPENSSL_LINE);
  422 | #else
  423 | 	return malloc(size); // IGNORE memory-check
  424 | #endif
  425 | }
  426 |
  427 | OQS_API void *OQS_MEM_calloc(size_t num_elements, size_t element_size) {
  428 | #if defined(OQS_USE_OPENSSL)
  429 | 	if (element_size != 0 && num_elements > SIZE_MAX / element_size) {
  430 | 		return NULL;
  431 | 	}
  432 | 	return OSSL_FUNC(CRYPTO_zalloc)(num_elements * element_size,
  433 | 	                                OPENSSL_FILE, OPENSSL_LINE);
  434 | #else
  435 | 	return calloc(num_elements, element_size); // IGNORE memory-check
  436 | #endif
  437 | }
  438 |
  439 | OQS_API char *OQS_MEM_strdup(const char *str) {
  440 | #if defined(OQS_USE_OPENSSL)
  441 | 	return OSSL_FUNC(CRYPTO_strdup)(str, OPENSSL_FILE, OPENSSL_LINE);
  442 | #elif defined(OQS_EMBEDDED_BUILD)
  443 | 	size_t len = strlen(str) + 1;
  444 | 	char *dup = (char *)malloc(len); // IGNORE memory-check
  445 | 	if (dup != NULL) {
  446 | 		memcpy(dup, str, len);
  447 | 	}
  448 | 	return dup;
  449 | #else
  450 | 	return strdup(str); // IGNORE memory-check
  451 | #endif
  452 | }

Reach line at /src/liboqs/src/common/common.c:414 (observed count 2850000).


   1 | /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   2 |  * SPDX-License-Identifier: Apache-2.0"
   3 |  *
   4 |  * Written by Nir Drucker, Shay Gueron and Dusan Kostic,
   5 |  * AWS Cryptographic Algorithms Group.
   6 |  */
   7 |
   8 | #include <assert.h>
   9 |
  10 | #include "sampling_internal.h"
  11 |
  12 | #define AVX2_INTERNAL
  13 | #include "x86_64_intrinsic.h"
  14 |
  15 | // For improved performance, we process NUM_YMMS amount of data in parallel.
  16 | #define NUM_YMMS    (4)
  17 | #define YMMS_QWORDS (QWORDS_IN_YMM * NUM_YMMS)
  18 |
  19 | void secure_set_bits_avx2(OUT pad_r_t *   r,
  20 |                           IN const size_t first_pos,
  21 |                           IN const idx_t *wlist,
  22 |                           IN const size_t w_size)
  23 | {
  24 |   // The function assumes that the size of r is a multiple
  25 |   // of the cumulative size of used YMM registers.
  26 |   assert((sizeof(*r) / sizeof(uint64_t)) % YMMS_QWORDS == 0);
  27 |
  28 |   // va vectors hold the bits of the output array "r"
  29 |   // va_pos_qw vectors hold the qw position indices of "r"
  30 |   // The algorithm works as follows:
  31 |   //   1. Initialize va_pos_qw with starting positions of qw's of "r"
  32 |   //      va_pos_qw = (3, 2, 1, 0);
  33 |   //   2. While the size of "r" is not exceeded:
  34 |   //   3.   For each w in wlist:
  35 |   //   4.     Compare the pos_qw of w with positions in va_pos_qw
  36 |   //          and for the position which is equal set the appropriate
  37 |   //          bit in va vector.
  38 |   //   5.   Set va_pos_qw to the next qw positions of "r"
  39 |   __m256i va[NUM_YMMS], va_pos_qw[NUM_YMMS], va_mask;
  40 |   __m256i w_pos_qw, w_pos_bit;
  41 |   __m256i one, inc;
  42 |
  43 |   uint64_t *r64 = (uint64_t *)r;
  44 |
  45 |   one = SET1_I64(1);
  46 |   inc = SET1_I64(QWORDS_IN_YMM);
  47 |
  48 |   // 1. Initialize
  49 |   va_pos_qw[0] = SET_I64(3, 2, 1, 0);
  50 |   for(size_t i = 1; i < NUM_YMMS; i++) {
  51 |     va_pos_qw[i] = ADD_I64(va_pos_qw[i - 1], inc);
  52 |   }
  53 |
  54 |   // va_pos_qw vectors hold qw positions 0 .. (NUM_YMMS * QWORDS_IN_YMM - 1)
  55 |   // Therefore, we set the increment vector inc such that by adding it to
  56 |   // va_pos_qw vectors, they hold the next YMM_QWORDS qw positions.
> 57 |   inc = SET1_I64(YMMS_QWORDS);
  58 |
  59 |   for(size_t i = 0; i < (sizeof(*r) / sizeof(uint64_t)); i += YMMS_QWORDS) {
  60 |     for(size_t va_iter = 0; va_iter < NUM_YMMS; va_iter++) {
  61 |       va[va_iter] = SET_ZERO;
  62 |     }
  63 |
  64 |     for(size_t w_iter = 0; w_iter < w_size; w_iter++) {
  65 |       int32_t w = wlist[w_iter] - first_pos;
  66 |       w_pos_qw  = SET1_I64(w >> 6);
  67 |       w_pos_bit = SLLI_I64(one, w & MASK(6));
  68 |
  69 |       // 4. Compare the positions in va_pos_qw with w_pos_qw
  70 |       //    and set the appropriate bit in va
  71 |       for(size_t va_iter = 0; va_iter < NUM_YMMS; va_iter++) {
  72 |         va_mask = CMPEQ_I64(va_pos_qw[va_iter], w_pos_qw);
  73 |         va[va_iter] |= (va_mask & w_pos_bit);
  74 |       }
  75 |     }
  76 |
  77 |     // 5. Set the va_pos_qw to the next qw positions of r
  78 |     //    and store the previously computed data in r
  79 |     for(size_t va_iter = 0; va_iter < NUM_YMMS; va_iter++) {
  80 |       STORE(&r64[i + (va_iter * QWORDS_IN_YMM)], va[va_iter]);
  81 |       va_pos_qw[va_iter] = ADD_I64(va_pos_qw[va_iter], inc);
  82 |     }
  83 |   }
  84 | }
  85 |

Reach line at /src/liboqs/src/kem/bike/additional_r4/sampling_avx2.c:57 (observed count 84).


    1 | // SPDX-License-Identifier: MIT
    2 |
    3 | #include <oqs/oqs.h>
    4 |
    5 | #include "sha3.h"
    6 |
    7 | extern struct OQS_SHA3_callbacks sha3_default_callbacks;
    8 |
    9 | static struct OQS_SHA3_callbacks *callbacks = &sha3_default_callbacks;
   10 |
   11 | OQS_API void OQS_SHA3_set_callbacks(struct OQS_SHA3_callbacks *new_callbacks) {
   12 | 	callbacks = new_callbacks;
   13 | }
   14 |
   15 | void OQS_SHA3_sha3_256(uint8_t *output, const uint8_t *input, size_t inplen) {
   16 | 	callbacks->SHA3_sha3_256(output, input, inplen);
   17 | }
   18 |
   19 | void OQS_SHA3_sha3_256_inc_init(OQS_SHA3_sha3_256_inc_ctx *state) {
   20 | 	callbacks->SHA3_sha3_256_inc_init(state);
   21 | }
   22 |
   23 | void OQS_SHA3_sha3_256_inc_absorb(OQS_SHA3_sha3_256_inc_ctx *state, const uint8_t *input, size_t inlen) {
   24 | 	callbacks->SHA3_sha3_256_inc_absorb(state, input, inlen);
   25 | }
   26 |
   27 | void OQS_SHA3_sha3_256_inc_finalize(uint8_t *output, OQS_SHA3_sha3_256_inc_ctx *state) {
   28 | 	callbacks->SHA3_sha3_256_inc_finalize(output, state);
   29 | }
   30 |
   31 | void OQS_SHA3_sha3_256_inc_ctx_release(OQS_SHA3_sha3_256_inc_ctx *state) {
   32 | 	callbacks->SHA3_sha3_256_inc_ctx_release(state);
   33 | }
   34 |
   35 | void OQS_SHA3_sha3_256_inc_ctx_reset(OQS_SHA3_sha3_256_inc_ctx *state) {
   36 | 	callbacks->SHA3_sha3_256_inc_ctx_reset(state);
   37 | }
   38 |
   39 | void OQS_SHA3_sha3_256_inc_ctx_clone(OQS_SHA3_sha3_256_inc_ctx *dest, const OQS_SHA3_sha3_256_inc_ctx *src) {
   40 | 	callbacks->SHA3_sha3_256_inc_ctx_clone(dest, src);
   41 | }
   42 |
   43 | void OQS_SHA3_sha3_384(uint8_t *output, const uint8_t *input, size_t inplen) {
   44 | 	callbacks->SHA3_sha3_384(output, input, inplen);
   45 | }
   46 |
   47 | void OQS_SHA3_sha3_384_inc_init(OQS_SHA3_sha3_384_inc_ctx *state) {
   48 | 	callbacks->SHA3_sha3_384_inc_init(state);
   49 | }
   50 |
   51 | void OQS_SHA3_sha3_384_inc_absorb(OQS_SHA3_sha3_384_inc_ctx *state, const uint8_t *input, size_t inlen) {
   52 | 	callbacks->SHA3_sha3_384_inc_absorb(state, input, inlen);
   53 | }
   54 |
   55 | void OQS_SHA3_sha3_384_inc_finalize(uint8_t *output, OQS_SHA3_sha3_384_inc_ctx *state) {
   56 | 	callbacks->SHA3_sha3_384_inc_finalize(output, state);
   57 | }
   58 |
   59 | void OQS_SHA3_sha3_384_inc_ctx_release(OQS_SHA3_sha3_384_inc_ctx *state) {
>  60 | 	callbacks->SHA3_sha3_384_inc_ctx_release(state);
   61 | }
   62 |
   63 | void OQS_SHA3_sha3_384_inc_ctx_reset(OQS_SHA3_sha3_384_inc_ctx *state) {
   64 | 	callbacks->SHA3_sha3_384_inc_ctx_reset(state);
   65 | }
   66 |
   67 | void OQS_SHA3_sha3_384_inc_ctx_clone(OQS_SHA3_sha3_384_inc_ctx *dest, const OQS_SHA3_sha3_384_inc_ctx *src) {
   68 | 	callbacks->SHA3_sha3_384_inc_ctx_clone(dest, src);
   69 | }
   70 |
   71 | void OQS_SHA3_sha3_512(uint8_t *output, const uint8_t *input, size_t inplen) {
   72 | 	callbacks->SHA3_sha3_512(output, input, inplen);
   73 | }
   74 |
   75 | void OQS_SHA3_sha3_512_inc_init(OQS_SHA3_sha3_512_inc_ctx *state) {
   76 | 	callbacks->SHA3_sha3_512_inc_init(state);
   77 | }
   78 |
   79 | void OQS_SHA3_sha3_512_inc_absorb(OQS_SHA3_sha3_512_inc_ctx *state, const uint8_t *input, size_t inlen) {
   80 | 	callbacks->SHA3_sha3_512_inc_absorb(state, input, inlen);
   81 | }
   82 |
   83 | void OQS_SHA3_sha3_512_inc_finalize(uint8_t *output, OQS_SHA3_sha3_512_inc_ctx *state) {
   84 | 	callbacks->SHA3_sha3_512_inc_finalize(output, state);
   85 | }
   86 |
   87 | void OQS_SHA3_sha3_512_inc_ctx_release(OQS_SHA3_sha3_512_inc_ctx *state) {
   88 | 	callbacks->SHA3_sha3_512_inc_ctx_release(state);
   89 | }
   90 |
   91 | void OQS_SHA3_sha3_512_inc_ctx_reset(OQS_SHA3_sha3_512_inc_ctx *state) {
   92 | 	callbacks->SHA3_sha3_512_inc_ctx_reset(state);
   93 | }
   94 |
   95 | void OQS_SHA3_sha3_512_inc_ctx_clone(OQS_SHA3_sha3_512_inc_ctx *dest, const OQS_SHA3_sha3_512_inc_ctx *src) {
   96 | 	callbacks->SHA3_sha3_512_inc_ctx_clone(dest, src);
   97 | }
   98 |
   99 | void OQS_SHA3_shake128(uint8_t *output, size_t outlen, const uint8_t *input, size_t inplen) {
  100 | 	callbacks->SHA3_shake128(output, outlen, input, inplen);
  101 | }
  102 |
  103 | void OQS_SHA3_shake128_inc_init(OQS_SHA3_shake128_inc_ctx *state) {
  104 | 	callbacks->SHA3_shake128_inc_init(state);
  105 | }
  106 |
  107 | void OQS_SHA3_shake128_inc_absorb(OQS_SHA3_shake128_inc_ctx *state, const uint8_t *input, size_t inlen) {
  108 | 	callbacks->SHA3_shake128_inc_absorb(state, input, inlen);
  109 | }
  110 |
  111 | void OQS_SHA3_shake128_inc_finalize(OQS_SHA3_shake128_inc_ctx *state) {
  112 | 	callbacks->SHA3_shake128_inc_finalize(state);
  113 | }
  114 |
  115 | void OQS_SHA3_shake128_inc_squeeze(uint8_t *output, size_t outlen, OQS_SHA3_shake128_inc_ctx *state) {
  116 | 	callbacks->SHA3_shake128_inc_squeeze(output, outlen, state);
  117 | }
  118 |
  119 | void OQS_SHA3_shake128_inc_ctx_release(OQS_SHA3_shake128_inc_ctx *state) {
  120 | 	callbacks->SHA3_shake128_inc_ctx_release(state);
  121 | }
  122 |
  123 | void OQS_SHA3_shake128_inc_ctx_clone(OQS_SHA3_shake128_inc_ctx *dest, const OQS_SHA3_shake128_inc_ctx *src) {
  124 | 	callbacks->SHA3_shake128_inc_ctx_clone(dest, src);
  125 | }
  126 |
  127 | void OQS_SHA3_shake128_inc_ctx_reset(OQS_SHA3_shake128_inc_ctx *state) {
  128 | 	callbacks->SHA3_shake128_inc_ctx_reset(state);
  129 | }
  130 |
  131 | void OQS_SHA3_shake256(uint8_t *output, size_t outlen, const uint8_t *input, size_t inplen) {
  132 | 	callbacks->SHA3_shake256(output, outlen, input, inplen);
  133 | }
  134 |
  135 | void OQS_SHA3_shake256_inc_init(OQS_SHA3_shake256_inc_ctx *state) {
  136 | 	callbacks->SHA3_shake256_inc_init(state);
  137 | }
  138 |
  139 | void OQS_SHA3_shake256_inc_absorb(OQS_SHA3_shake256_inc_ctx *state, const uint8_t *input, size_t inlen) {
  140 | 	callbacks->SHA3_shake256_inc_absorb(state, input, inlen);
  141 | }
  142 |
  143 | void OQS_SHA3_shake256_inc_finalize(OQS_SHA3_shake256_inc_ctx *state) {
  144 | 	callbacks->SHA3_shake256_inc_finalize(state);
  145 | }
  146 |
  147 | void OQS_SHA3_shake256_inc_squeeze(uint8_t *output, size_t outlen, OQS_SHA3_shake256_inc_ctx *state) {
  148 | 	callbacks->SHA3_shake256_inc_squeeze(output, outlen, state);
  149 | }
  150 |
  151 | void OQS_SHA3_shake256_inc_ctx_release(OQS_SHA3_shake256_inc_ctx *state) {
  152 | 	callbacks->SHA3_shake256_inc_ctx_release(state);
  153 | }
  154 |
  155 | void OQS_SHA3_shake256_inc_ctx_clone(OQS_SHA3_shake256_inc_ctx *dest, const OQS_SHA3_shake256_inc_ctx *src) {
  156 | 	callbacks->SHA3_shake256_inc_ctx_clone(dest, src);
  157 | }
  158 |
  159 | void OQS_SHA3_shake256_inc_ctx_reset(OQS_SHA3_shake256_inc_ctx *state) {
  160 | 	callbacks->SHA3_shake256_inc_ctx_reset(state);

Reach line at /src/liboqs/src/common/sha3/sha3.c:60 (observed count 28).


   89 |                                  const uint8_t *in0, const uint8_t *in1, const uint8_t *in2, const uint8_t *in3, size_t inlen) {
   90 | 	uint64_t c = r - s[100];
   91 |
   92 | 	if (s[100] && inlen >= c) {
   93 | 		(*Keccak_X4_AddBytes_ptr)(s, 0, in0, (unsigned int)s[100], (unsigned int)c);
   94 | 		(*Keccak_X4_AddBytes_ptr)(s, 1, in1, (unsigned int)s[100], (unsigned int)c);
   95 | 		(*Keccak_X4_AddBytes_ptr)(s, 2, in2, (unsigned int)s[100], (unsigned int)c);
   96 | 		(*Keccak_X4_AddBytes_ptr)(s, 3, in3, (unsigned int)s[100], (unsigned int)c);
   97 | 		(*Keccak_X4_Permute_ptr)(s);
   98 | 		inlen -= c;
   99 | 		in0 += c;
  100 | 		in1 += c;
  101 | 		in2 += c;
  102 | 		in3 += c;
  103 | 		s[100] = 0;
  104 | 	}
  105 |
  106 | 	while (inlen >= r) {
  107 | 		(*Keccak_X4_AddBytes_ptr)(s, 0, in0, 0, (unsigned int)r);
  108 | 		(*Keccak_X4_AddBytes_ptr)(s, 1, in1, 0, (unsigned int)r);
  109 | 		(*Keccak_X4_AddBytes_ptr)(s, 2, in2, 0, (unsigned int)r);
  110 | 		(*Keccak_X4_AddBytes_ptr)(s, 3, in3, 0, (unsigned int)r);
  111 | 		(*Keccak_X4_Permute_ptr)(s);
  112 | 		inlen -= r;
  113 | 		in0 += r;
  114 | 		in1 += r;
  115 | 		in2 += r;
  116 | 		in3 += r;
  117 | 	}
  118 |
  119 | 	(*Keccak_X4_AddBytes_ptr)(s, 0, in0, (unsigned int)s[100], (unsigned int)inlen);
  120 | 	(*Keccak_X4_AddBytes_ptr)(s, 1, in1, (unsigned int)s[100], (unsigned int)inlen);
  121 | 	(*Keccak_X4_AddBytes_ptr)(s, 2, in2, (unsigned int)s[100], (unsigned int)inlen);
  122 | 	(*Keccak_X4_AddBytes_ptr)(s, 3, in3, (unsigned int)s[100], (unsigned int)inlen);
  123 | 	s[100] += inlen;
  124 | }
  125 |
  126 | static void keccak_x4_inc_finalize(uint64_t *s, uint32_t r, uint8_t p) {
  127 | 	(*Keccak_X4_AddByte_ptr)(s, 0, p, (unsigned int)s[100]);
  128 | 	(*Keccak_X4_AddByte_ptr)(s, 1, p, (unsigned int)s[100]);
  129 | 	(*Keccak_X4_AddByte_ptr)(s, 2, p, (unsigned int)s[100]);
  130 | 	(*Keccak_X4_AddByte_ptr)(s, 3, p, (unsigned int)s[100]);
  131 |
  132 | 	(*Keccak_X4_AddByte_ptr)(s, 0, 0x80, (unsigned int)(r - 1));
  133 | 	(*Keccak_X4_AddByte_ptr)(s, 1, 0x80, (unsigned int)(r - 1));
  134 | 	(*Keccak_X4_AddByte_ptr)(s, 2, 0x80, (unsigned int)(r - 1));
  135 | 	(*Keccak_X4_AddByte_ptr)(s, 3, 0x80, (unsigned int)(r - 1));
  136 |
  137 | 	s[100] = 0;
  138 | }
  139 |
  140 | static void keccak_x4_inc_squeeze(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_t *out3,
  141 |                                   size_t outlen, uint64_t *s, uint32_t r) {
  142 |
  143 | 	while (outlen > s[100]) {
  144 | 		(*Keccak_X4_ExtractBytes_ptr)(s, 0, out0, (unsigned int)(r - s[100]), (unsigned int)s[100]);
  145 | 		(*Keccak_X4_ExtractBytes_ptr)(s, 1, out1, (unsigned int)(r - s[100]), (unsigned int)s[100]);
  146 | 		(*Keccak_X4_ExtractBytes_ptr)(s, 2, out2, (unsigned int)(r - s[100]), (unsigned int)s[100]);
  147 | 		(*Keccak_X4_ExtractBytes_ptr)(s, 3, out3, (unsigned int)(r - s[100]), (unsigned int)s[100]);
  148 | 		(*Keccak_X4_Permute_ptr)(s);
  149 | 		out0 += s[100];
  150 | 		out1 += s[100];
  151 | 		out2 += s[100];
  152 | 		out3 += s[100];
  153 | 		outlen -= s[100];
  154 | 		s[100] = r;
  155 | 	}
  156 |
  157 | 	(*Keccak_X4_ExtractBytes_ptr)(s, 0, out0, (unsigned int)(r - s[100]), (unsigned int)outlen);
  158 | 	(*Keccak_X4_ExtractBytes_ptr)(s, 1, out1, (unsigned int)(r - s[100]), (unsigned int)outlen);
  159 | 	(*Keccak_X4_ExtractBytes_ptr)(s, 2, out2, (unsigned int)(r - s[100]), (unsigned int)outlen);
  160 | 	(*Keccak_X4_ExtractBytes_ptr)(s, 3, out3, (unsigned int)(r - s[100]), (unsigned int)outlen);
  161 |
  162 | 	s[100] -= outlen;
  163 | }
  164 |
  165 | /********** SHAKE128 ***********/
  166 |
  167 | static void SHA3_shake128_x4(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_t *out3, size_t outlen, const uint8_t *in0, const uint8_t *in1, const uint8_t *in2, const uint8_t *in3, size_t inlen) {
  168 | 	OQS_SHA3_shake128_x4_inc_ctx s;
  169 | 	OQS_SHA3_shake128_x4_inc_init(&s);
  170 | 	OQS_SHA3_shake128_x4_inc_absorb(&s, in0, in1, in2, in3, inlen);
  171 | 	OQS_SHA3_shake128_x4_inc_finalize(&s);
  172 | 	OQS_SHA3_shake128_x4_inc_squeeze(out0, out1, out2, out3, outlen, &s);
  173 | 	OQS_SHA3_shake128_x4_inc_ctx_release(&s);
  174 | }
  175 |
  176 | /* SHAKE128 incremental */
  177 |
  178 | static void SHA3_shake128_x4_inc_init(OQS_SHA3_shake128_x4_inc_ctx *state) {
  179 | 	state->ctx = OQS_MEM_aligned_alloc(KECCAK_X4_CTX_ALIGNMENT, KECCAK_X4_CTX_BYTES);
  180 | 	OQS_EXIT_IF_NULLPTR(state->ctx, "SHA3x4");
  181 | 	keccak_x4_inc_reset((uint64_t *)state->ctx);
  182 | }
  183 | static void SHA3_shake128_x4_inc_absorb(OQS_SHA3_shake128_x4_inc_ctx *state, const uint8_t *in0, const uint8_t *in1, const uint8_t *in2, const uint8_t *in3, size_t inlen) {
  184 | 	keccak_x4_inc_absorb((uint64_t *)state->ctx, OQS_SHA3_SHAKE128_RATE, in0, in1, in2, in3, inlen);
  185 | }
  186 |
  187 | static void SHA3_shake128_x4_inc_finalize(OQS_SHA3_shake128_x4_inc_ctx *state) {
  188 | 	keccak_x4_inc_finalize((uint64_t *)state->ctx, OQS_SHA3_SHAKE128_RATE, 0x1F);
> 189 | }
  190 |
  191 | static void SHA3_shake128_x4_inc_squeeze(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_t *out3, size_t outlen, OQS_SHA3_shake128_x4_inc_ctx *state) {
  192 | 	keccak_x4_inc_squeeze(out0, out1, out2, out3, outlen, (uint64_t *)state->ctx, OQS_SHA3_SHAKE128_RATE);
  193 | }
  194 |
  195 | static void SHA3_shake128_x4_inc_ctx_clone(OQS_SHA3_shake128_x4_inc_ctx *dest, const OQS_SHA3_shake128_x4_inc_ctx *src) {
  196 | 	memcpy(dest->ctx, src->ctx, KECCAK_X4_CTX_BYTES);
  197 | }
  198 |
  199 | static void SHA3_shake128_x4_inc_ctx_release(OQS_SHA3_shake128_x4_inc_ctx *state) {
  200 | 	OQS_MEM_aligned_secure_free(state->ctx, KECCAK_X4_CTX_BYTES);
  201 | }
  202 |
  203 | static void SHA3_shake128_x4_inc_ctx_reset(OQS_SHA3_shake128_x4_inc_ctx *state) {
  204 | 	keccak_x4_inc_reset((uint64_t *)state->ctx);
  205 | }
  206 |
  207 | /********** SHAKE256 ***********/
  208 |
  209 | static void SHA3_shake256_x4(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_t *out3, size_t outlen, const uint8_t *in0, const uint8_t *in1, const uint8_t *in2, const uint8_t *in3, size_t inlen) {
  210 | 	OQS_SHA3_shake256_x4_inc_ctx s;
  211 | 	OQS_SHA3_shake256_x4_inc_init(&s);
  212 | 	OQS_SHA3_shake256_x4_inc_absorb(&s, in0, in1, in2, in3, inlen);
  213 | 	OQS_SHA3_shake256_x4_inc_finalize(&s);
  214 | 	OQS_SHA3_shake256_x4_inc_squeeze(out0, out1, out2, out3, outlen, &s);
  215 | 	OQS_SHA3_shake256_x4_inc_ctx_release(&s);
  216 | }
  217 |
  218 | /* SHAKE256 incremental */
  219 |
  220 | static void SHA3_shake256_x4_inc_init(OQS_SHA3_shake256_x4_inc_ctx *state) {
  221 | 	state->ctx = OQS_MEM_aligned_alloc(KECCAK_X4_CTX_ALIGNMENT, KECCAK_X4_CTX_BYTES);
  222 | 	OQS_EXIT_IF_NULLPTR(state->ctx, "SHA3x4");
  223 | 	keccak_x4_inc_reset((uint64_t *)state->ctx);
  224 | }
  225 |
  226 | static void SHA3_shake256_x4_inc_absorb(OQS_SHA3_shake256_x4_inc_ctx *state, const uint8_t *in0, const uint8_t *in1, const uint8_t *in2, const uint8_t *in3, size_t inlen) {
  227 | 	keccak_x4_inc_absorb((uint64_t *)state->ctx, OQS_SHA3_SHAKE256_RATE, in0, in1, in2, in3, inlen);
  228 | }
  229 |
  230 | static void SHA3_shake256_x4_inc_finalize(OQS_SHA3_shake256_x4_inc_ctx *state) {
  231 | 	keccak_x4_inc_finalize((uint64_t *)state->ctx, OQS_SHA3_SHAKE256_RATE, 0x1F);
  232 | }
  233 |
  234 | static void SHA3_shake256_x4_inc_squeeze(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_t *out3, size_t outlen, OQS_SHA3_shake256_x4_inc_ctx *state) {
  235 | 	keccak_x4_inc_squeeze(out0, out1, out2, out3, outlen, (uint64_t *)state->ctx, OQS_SHA3_SHAKE256_RATE);
  236 | }
  237 |
  238 | static void SHA3_shake256_x4_inc_ctx_clone(OQS_SHA3_shake256_x4_inc_ctx *dest, const OQS_SHA3_shake256_x4_inc_ctx *src) {
  239 | 	memcpy(dest->ctx, src->ctx, KECCAK_X4_CTX_BYTES);
  240 | }
  241 |
  242 | static void SHA3_shake256_x4_inc_ctx_release(OQS_SHA3_shake256_x4_inc_ctx *state) {
  243 | 	OQS_MEM_aligned_secure_free(state->ctx, KECCAK_X4_CTX_BYTES);
  244 | }
  245 |
  246 | static void SHA3_shake256_x4_inc_ctx_reset(OQS_SHA3_shake256_x4_inc_ctx *state) {
  247 | 	keccak_x4_inc_reset((uint64_t *)state->ctx);
  248 | }
  249 |
  250 | struct OQS_SHA3_x4_callbacks sha3_x4_default_callbacks = {
  251 | 	SHA3_shake128_x4,
  252 | 	SHA3_shake128_x4_inc_init,
  253 | 	SHA3_shake128_x4_inc_absorb,
  254 | 	SHA3_shake128_x4_inc_finalize,
  255 | 	SHA3_shake128_x4_inc_squeeze,
  256 | 	SHA3_shake128_x4_inc_ctx_release,
  257 | 	SHA3_shake128_x4_inc_ctx_clone,
  258 | 	SHA3_shake128_x4_inc_ctx_reset,
  259 | 	SHA3_shake256_x4,
  260 | 	SHA3_shake256_x4_inc_init,
  261 | 	SHA3_shake256_x4_inc_absorb,
  262 | 	SHA3_shake256_x4_inc_finalize,
  263 | 	SHA3_shake256_x4_inc_squeeze,
  264 | 	SHA3_shake256_x4_inc_ctx_release,
  265 | 	SHA3_shake256_x4_inc_ctx_clone,
  266 | 	SHA3_shake256_x4_inc_ctx_reset,
  267 | };

Reach line at /src/liboqs/src/common/sha3/xkcp_sha3x4.c:189 (observed count 338000).


  270 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x285, maxlen))
  271 |       SubVersion = 4;
  272 | // printf ("==>> CanonID_EOS_1D_X, SubVersion: %d\n", SubVersion);
  273 |
  274 |     if (SubVersion < 3)
  275 |       SubVersion_offset += -3;
  276 |
  277 |     iCanonCurFocal  =  0x23+SubVersion_offset;
  278 |     iMakernotesFlip =  0x7d+SubVersion_offset;
  279 |
  280 |     if (SubVersion < 3)
  281 |       SubVersion_offset += -4;
  282 |     else if (SubVersion == 4)
  283 |       SubVersion_offset += 5;
  284 |
  285 |     iCanonLensID    = 0x1a7+SubVersion_offset;
  286 |     iCanonMinFocal  = 0x1a9+SubVersion_offset;
  287 |     iCanonMaxFocal  = 0x1ab+SubVersion_offset;
  288 |     break;
  289 |
  290 |   case CanonID_EOS_5D:
  291 |     iMakernotesFlip =  0x27;
  292 |     iCanonCurFocal  =  0x28;
  293 |     iCanonLensID    =  0x0c;
  294 |     if (!sget2Rev(CameraInfo + iCanonLensID))
  295 |       iCanonLensID  =  0x97;
  296 |     iCanonMinFocal  =  0x93;
  297 |     iCanonMaxFocal  =  0x95;
  298 |     break;
  299 |
  300 |   case CanonID_EOS_5D_Mark_II:
  301 |     iHTP            =  0x07;
  302 |     iCanonCurFocal  =  0x1e;
  303 |     iMakernotesFlip =  0x31;
  304 |     iALO            =  0xbf;
  305 |     iCanonLensID    =  0xe6;
  306 |     iCanonMinFocal  =  0xe8;
  307 |     iCanonMaxFocal  =  0xea;
  308 |     break;
  309 |
  310 |   case CanonID_EOS_5D_Mark_III:
  311 |     if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x22c, maxlen))
  312 |       SubVersion = 1;
  313 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x22d, maxlen))
  314 |       SubVersion = 2;
  315 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x23c, maxlen))
  316 |       SubVersion = 3;
  317 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x242, maxlen))
  318 |       SubVersion = 4;
  319 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x247, maxlen))
  320 |       SubVersion = 5;
  321 | // printf ("==>> CanonID_EOS_5D_Mark_III, SubVersion: %d\n", SubVersion);
  322 |
  323 |     if (!SubVersion)
  324 |       break;
  325 |     else if (SubVersion < 3)
  326 |       SubVersion_offset += -1;
  327 |
  328 |     iCanonCurFocal  =  0x23+SubVersion_offset;
  329 |
  330 |     if (SubVersion == 1)
  331 |       SubVersion_offset += -3;
  332 |     else if (SubVersion == 2)
  333 |       SubVersion_offset += -2;
  334 |     else if (SubVersion >= 4)
  335 |       SubVersion_offset += 6;
  336 |
  337 |     iMakernotesFlip =  0x7d+SubVersion_offset;
  338 |
  339 |     if (SubVersion < 3)
  340 |       SubVersion_offset += -4;
  341 |     else if (SubVersion > 4)
  342 |       SubVersion_offset += 5;
  343 |
  344 |     iCanonLensID    = 0x153+SubVersion_offset;
  345 |     iCanonMinFocal  = 0x155+SubVersion_offset;
  346 |     iCanonMaxFocal  = 0x157+SubVersion_offset;
  347 |     break;
  348 |
  349 |   case CanonID_EOS_5D_Mark_IV:
  350 |     iMakernotesFlip =  0x96;
  351 |     iAutoRotateMode = 0x5da;
  352 |     //printf ("==>> 5DMkIV: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
  353 |     break;
  354 |
  355 |   case CanonID_EOS_5DS:
  356 |   case CanonID_EOS_5DS_R:
  357 |     iMakernotesFlip =  0x96;
  358 |     iAutoRotateMode = 0x580;
  359 |     //printf ("==>> 5DS/5DS R: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
  360 |     break;
  361 |
  362 |   case CanonID_EOS_6D:
  363 |     iCanonCurFocal  =  0x23;
  364 |     iMakernotesFlip =  0x83;
  365 |     iCanonLensID    = 0x161;
  366 |     iCanonMinFocal  = 0x163;
  367 |     iCanonMaxFocal  = 0x165;
  368 |     iAutoRotateMode = 0x3b2;
  369 |     //printf ("==>> 6D: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
> 370 |     break;
  371 |
  372 |   case CanonID_EOS_7D:
  373 |     if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1a8, maxlen))
  374 |       SubVersion = 1;
  375 |     else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1ac, maxlen))
  376 |       SubVersion = 2;
  377 | // printf ("==>> CanonID_EOS_7D, SubVersion: %d\n", SubVersion);
  378 |     iHTP            =  0x07;
  379 |     iCanonCurFocal  =  0x1e;
  380 |
  381 |     if (!SubVersion)
  382 |       break;
  383 |     else if (SubVersion < 2)
  384 |       SubVersion_offset += -4;
  385 |
  386 |     iMakernotesFlip =  0x35+SubVersion_offset;
  387 |     iCanonLensID    = 0x112+SubVersion_offset;
  388 |     iCanonMinFocal  = 0x114+SubVersion_offset;
  389 |     iCanonMaxFocal  = 0x116+SubVersion_offset;
  390 |     break;
  391 |
  392 |   case CanonID_EOS_40D:
  393 |     iCanonCurFocal  =  0x1d;
  394 |     iMakernotesFlip =  0x30;
  395 |     iCanonLensID    =  0xd6;
  396 |     iCanonMinFocal  =  0xd8;
  397 |     iCanonMaxFocal  =  0xda;
  398 |     iCanonLens      = 0x92b;
  399 |     break;
  400 |
  401 |   case CanonID_EOS_50D:
  402 |     iHTP            =  0x07;
  403 |     iCanonCurFocal  =  0x1e;
  404 |     iMakernotesFlip =  0x31;
  405 |     iALO            =  0xbf;
  406 |     iCanonLensID    =  0xea;
  407 |     iCanonMinFocal  =  0xec;
  408 |     iCanonMaxFocal  =  0xee;
  409 |     break;
  410 |
  411 |   case CanonID_EOS_60D:
  412 |   case CanonID_EOS_1200D:
  413 |     iCanonCurFocal  =  0x1e;
  414 |     if (id == CanonID_EOS_60D)
  415 |       iMakernotesFlip =  0x36;
  416 |     else
  417 |       iMakernotesFlip =  0x3a;
  418 |     iCanonLensID    =  0xe8;
  419 |     iCanonMinFocal  =  0xea;
  420 |     iCanonMaxFocal  =  0xec;
  421 |     break;
  422 |
  423 |   case CanonID_EOS_70D:
  424 |     iCanonCurFocal  =  0x23;
  425 |     iMakernotesFlip =  0x84;
  426 |     iCanonLensID    = 0x166;
  427 |     iCanonMinFocal  = 0x168;
  428 |     iCanonMaxFocal  = 0x16a;
  429 |     break;
  430 |
  431 |   case CanonID_EOS_80D:
  432 |     iCanonCurFocal  =  0x23;
  433 |     iMakernotesFlip =  0x96;
  434 |     iCanonLensID    = 0x189;
  435 |     iCanonMinFocal  = 0x18b;
  436 |     iCanonMaxFocal  = 0x18d;
  437 |     break;
  438 |
  439 |   case CanonID_EOS_450D:
  440 |     iCanonCurFocal  =  0x1d;
  441 |     iMakernotesFlip =  0x30;
  442 |     iCanonLensID    =  0xde;
  443 |     iCanonLens      = 0x933;
  444 |     break;
  445 |
  446 |   case CanonID_EOS_500D:
  447 |     iHTP            =  0x07;
  448 |     iCanonCurFocal  =  0x1e;
  449 |     iMakernotesFlip =  0x31;
  450 |     iALO            =  0xbe;
  451 |     iCanonLensID    =  0xf6;
  452 |     iCanonMinFocal  =  0xf8;
  453 |     iCanonMaxFocal  =  0xfa;
  454 |     break;
  455 |
  456 |   case CanonID_EOS_550D:
  457 |     iHTP            =  0x07;
  458 |     iCanonCurFocal  =  0x1e;
  459 |     iMakernotesFlip =  0x35;
  460 |     iCanonLensID    =  0xff;
  461 |     iCanonMinFocal  = 0x101;
  462 |     iCanonMaxFocal  = 0x103;
  463 |     break;
  464 |
  465 |   case CanonID_EOS_600D:
  466 |   case CanonID_EOS_1100D:
  467 |     iHTP            =  0x07;
  468 |     iCanonCurFocal  =  0x1e;
  469 |     iMakernotesFlip =  0x38;
  470 |     iCanonLensID    =  0xea;

Reach line at /src/libraw/src/metadata/canon.cpp:370 (observed count 1950).


Reach line at /src/libraw/src/demosaic/xtrans_demosaic.cpp:390 (observed count 3160).


  1150 |       bond->setProp(common_properties::_MolFileBondCfg, cfg);
  1151 |       bond->setBondDir(state);
  1152 |       if (cfg == 2 && canHaveDirection(*bond)) {
  1153 |         bond->getBeginAtom()->setChiralTag(Atom::ChiralType::CHI_UNSPECIFIED);
  1154 |         mol.setProp(detail::_needsDetectBondStereo, 1);
  1155 |       }
  1156 |       if ((cfg == 1 || cfg == 3) && canHaveDirection(*bond)) {
  1157 |         mol.setProp(detail::_needsDetectAtomStereo, 1);
  1158 |       }
  1159 |     }
  1160 |     if (first < last && *first == ',') {
  1161 |       ++first;
  1162 |     }
  1163 |   }
  1164 |   return true;
  1165 | }
  1166 |
  1167 | template <typename Iterator>
  1168 | bool parse_doublebond_stereo(Iterator &first, Iterator last, RDKit::RWMol &mol,
  1169 |                              unsigned int, unsigned int startBondIdx,
  1170 |                              Bond::BondStereo stereo) {
  1171 |   // these look like: C1CCCC/C=C/CCC1 |ctu:5|
  1172 |   // also c and t for cis or trans
  1173 |   //
  1174 |   while (first < last && *first != ':') {
  1175 |     ++first;
  1176 |   }
  1177 |   if (first >= last || *first != ':') {
  1178 |     return false;
  1179 |   }
  1180 |   ++first;
  1181 |
  1182 |   while (first < last && *first >= '0' && *first <= '9') {
  1183 |     unsigned int bondIdx;
  1184 |     if (!read_int(first, last, bondIdx)) {
  1185 |       return false;
  1186 |     }
  1187 |     if (VALID_BNDIDX(bondIdx)) {
  1188 |       auto bond = get_bond_with_smiles_idx(mol, bondIdx - startBondIdx);
  1189 |
  1190 |       if (!bond) {
  1191 |         BOOST_LOG(rdWarningLog)
  1192 |             << "bond " << bondIdx
  1193 |             << " not found, cannot mark as stereo double bond." << std::endl;
  1194 |         return false;
  1195 |       }
  1196 |
  1197 |       bool useCXOrdering = true;
  1198 |       Chirality::detail::setStereoForBond(mol, bond, stereo, useCXOrdering);
  1199 |     }
  1200 |     if (first < last && *first == ',') {
  1201 |       ++first;
  1202 |     }
  1203 |   }
  1204 |   return true;
  1205 | }
  1206 |
  1207 | template <typename Iterator>
  1208 | bool parse_substitution(Iterator &first, Iterator last, RDKit::RWMol &mol,
  1209 |                         unsigned int startAtomIdx) {
  1210 |   if (first >= last || *first != 's' || first + 1 >= last ||
  1211 |       *(first + 1) != ':') {
  1212 |     return false;
  1213 |   }
  1214 |   first += 2;
  1215 |   while (first < last && *first >= '0' && *first <= '9') {
  1216 |     unsigned int n1;
  1217 |     if (!read_int(first, last, n1)) {
  1218 |       return false;
  1219 |     }
  1220 |     // check that we can read at least two more characters:
  1221 |     if (first + 1 >= last || *first != ':') {
  1222 |       return false;
  1223 |     }
  1224 |     ++first;
  1225 |     unsigned int n2;
  1226 |     if (*first == '*') {
  1227 |       ++first;
  1228 |       n2 = 0xDEADBEEF;
  1229 |       if (VALID_ATIDX(n1)) {
  1230 |         mol.setProp(common_properties::_NeedsQueryScan, 1);
  1231 |       }
  1232 |     } else {
  1233 |       if (!read_int(first, last, n2)) {
  1234 |         return false;
  1235 |       }
  1236 |     }
  1237 |     if (VALID_ATIDX(n1)) {
  1238 |       auto atom = mol.getAtomWithIdx(n1 - startAtomIdx);
  1239 |       if (!atom->hasQuery()) {
  1240 |         atom = QueryOps::replaceAtomWithQueryAtom(&mol, atom);
  1241 |       }
  1242 |       atom->expandQuery(makeAtomNonHydrogenDegreeQuery(n2),
  1243 |                         Queries::COMPOSITE_AND);
  1244 |     }
  1245 |     if (first < last && *first == ',') {
  1246 |       ++first;
  1247 |     }
  1248 |   }
  1249 |   return true;
> 1250 | }
  1251 |
  1252 | template <typename Iterator>
  1253 | bool processRadicalSection(Iterator &first, Iterator last, RDKit::RWMol &mol,
  1254 |                            unsigned int numRadicalElectrons,
  1255 |                            unsigned int startAtomIdx) {
  1256 |   if (first >= last) {
  1257 |     return false;
  1258 |   }
  1259 |   ++first;
  1260 |   if (first >= last || *first != ':') {
  1261 |     return false;
  1262 |   }
  1263 |   ++first;
  1264 |   unsigned int atIdx;
  1265 |   if (!read_int(first, last, atIdx)) {
  1266 |     return false;
  1267 |   }
  1268 |   if (VALID_ATIDX(atIdx)) {
  1269 |     mol.getAtomWithIdx(atIdx - startAtomIdx)
  1270 |         ->setNumRadicalElectrons(numRadicalElectrons);
  1271 |   }
  1272 |   while (first < last && *first == ',') {
  1273 |     ++first;
  1274 |     if (first < last && (*first < '0' || *first > '9')) {
  1275 |       return true;
  1276 |     }
  1277 |     if (!read_int(first, last, atIdx)) {
  1278 |       return false;
  1279 |     }
  1280 |     if (VALID_ATIDX(atIdx)) {
  1281 |       mol.getAtomWithIdx(atIdx - startAtomIdx)
  1282 |           ->setNumRadicalElectrons(numRadicalElectrons);
  1283 |     }
  1284 |   }
  1285 |   return first < last;
  1286 | }
  1287 |
  1288 | template <typename Iterator>
  1289 | bool parse_radicals(Iterator &first, Iterator last, RDKit::RWMol &mol,
  1290 |                     unsigned int startAtomIdx) {
  1291 |   if (first >= last || *first != '^') {
  1292 |     return false;
  1293 |   }
  1294 |   while (*first == '^') {
  1295 |     ++first;
  1296 |     if (first >= last) {
  1297 |       return false;
  1298 |     }
  1299 |     if (*first < '1' || *first > '7') {
  1300 |       return false;  // these are the values that are allowed to be there
  1301 |     }
  1302 |     switch (*first) {
  1303 |       case '1':
  1304 |         if (!processRadicalSection(first, last, mol, 1, startAtomIdx)) {
  1305 |           return false;
  1306 |         }
  1307 |         break;
  1308 |       case '2':
  1309 |       case '3':
  1310 |       case '4':
  1311 |         if (!processRadicalSection(first, last, mol, 2, startAtomIdx)) {
  1312 |           return false;
  1313 |         }
  1314 |         break;
  1315 |       case '5':
  1316 |       case '6':
  1317 |       case '7':
  1318 |         if (!processRadicalSection(first, last, mol, 3, startAtomIdx)) {
  1319 |           return false;
  1320 |         }
  1321 |         break;
  1322 |       default:
  1323 |         BOOST_LOG(rdWarningLog)
  1324 |             << "Radical specification " << *first << " ignored.";
  1325 |     }
  1326 |   }
  1327 |   return true;
  1328 | }
  1329 |
  1330 | template <typename Iterator>
  1331 | bool parse_enhanced_stereo(Iterator &first, Iterator last, RDKit::RWMol &mol,
  1332 |                            unsigned int startAtomIdx) {
  1333 |   StereoGroupType group_type = StereoGroupType::STEREO_ABSOLUTE;
  1334 |   if (*first == 'a') {
  1335 |     group_type = StereoGroupType::STEREO_ABSOLUTE;
  1336 |   } else if (*first == 'o') {
  1337 |     group_type = StereoGroupType::STEREO_OR;
  1338 |   } else if (*first == '&') {
  1339 |     group_type = StereoGroupType::STEREO_AND;
  1340 |   }
  1341 |   ++first;
  1342 |
  1343 |   // OR and AND groups carry a group number
  1344 |   unsigned int group_id = 0;
  1345 |   if (group_type != StereoGroupType::STEREO_ABSOLUTE) {
  1346 |     read_int(first, last, group_id);
  1347 |   }
  1348 |
  1349 |   if (first >= last || *first != ':') {
  1350 |     return false;

Reach line at /src/rdkit/Code/GraphMol/SmilesParse/CXSmilesOps.cpp:1250 (observed count 7720).


    1 | //
    2 | //  Copyright (C) 2001-2022 Greg Landrum and other RDKit contributors
    3 | //
    4 | //   @@ All Rights Reserved @@
    5 | //  This file is part of the RDKit.
    6 | //  The contents are covered by the terms of the BSD license
    7 | //  which is included in the file license.txt, found at the root
    8 | //  of the RDKit source tree.
    9 | //
   10 | #include <RDGeneral/export.h>
   11 | #ifndef RD_QUERYATOM_H
   12 | #define RD_QUERYATOM_H
   13 |
   14 | #include <utility>
   15 | #include "Atom.h"
   16 | #include <Query/QueryObjects.h>
   17 | #include <GraphMol/QueryOps.h>
   18 |
   19 | namespace RDKit {
   20 |
   21 | //! Class for storing atomic queries
   22 | /*!
   23 |   QueryAtom objects are derived from Atom objects, so they can be
   24 |   added to molecules and the like, but they have much fancier
   25 |   querying capabilities.
   26 |
   27 |  */
   28 | class RDKIT_GRAPHMOL_EXPORT QueryAtom : public Atom {
   29 |  public:
   30 |   typedef Queries::Query<int, Atom const *, true> QUERYATOM_QUERY;
   31 |
   32 |   QueryAtom() : Atom() {}
   33 |   explicit QueryAtom(int num) : Atom(num), dp_query(makeAtomNumQuery(num)) {}
   34 |   explicit QueryAtom(const Atom &other)
   35 |       : Atom(other), dp_query(makeAtomNumQuery(other.getAtomicNum())) {
   36 |     if (other.getIsotope()) {
   37 |       this->expandQuery(makeAtomIsotopeQuery(other.getIsotope()),
   38 |                         Queries::CompositeQueryType::COMPOSITE_AND);
   39 |     }
   40 |     if (other.getFormalCharge()) {
   41 |       this->expandQuery(makeAtomFormalChargeQuery(other.getFormalCharge()),
   42 |                         Queries::CompositeQueryType::COMPOSITE_AND);
   43 |     }
   44 |     if (other.getNumRadicalElectrons()) {
   45 |       this->expandQuery(
   46 |           makeAtomNumRadicalElectronsQuery(other.getNumRadicalElectrons()),
>  47 |           Queries::CompositeQueryType::COMPOSITE_AND);
   48 |     }
   49 |   }
   50 |   QueryAtom(const QueryAtom &other) : Atom(other) {
   51 |     if (other.dp_query) {
   52 |       dp_query = other.dp_query->copy();
   53 |     } else {
   54 |       dp_query = nullptr;
   55 |     }
   56 |   }
   57 |   QueryAtom &operator=(const QueryAtom &other) {
   58 |     if (this == &other) {
   59 |       return *this;
   60 |     }
   61 |     Atom::operator=(other);
   62 |     delete dp_query;
   63 |     if (other.dp_query) {
   64 |       dp_query = other.dp_query->copy();
   65 |     } else {
   66 |       dp_query = nullptr;
   67 |     }
   68 |     return *this;
   69 |   }
   70 |
   71 |   QueryAtom(QueryAtom &&other) noexcept : Atom(std::move(other)) {
   72 |     dp_query = std::exchange(other.dp_query, nullptr);
   73 |   }
   74 |   QueryAtom &operator=(QueryAtom &&other) noexcept {
   75 |     if (this == &other) {
   76 |       return *this;
   77 |     }
   78 |     QueryAtom::operator=(std::move(other));
   79 |     dp_query = std::exchange(other.dp_query, nullptr);
   80 |     return *this;
   81 |   }
   82 |
   83 |   ~QueryAtom() override;
   84 |
   85 |   //! returns a copy of this query, owned by the caller
   86 |   Atom *copy() const override;
   87 |
   88 |   // This method can be used to distinguish query atoms from standard atoms:
   89 |   bool hasQuery() const override { return dp_query != nullptr; }
   90 |
   91 |   //! returns the label associated to this query
   92 |   std::string getQueryType() const override { return dp_query->getTypeLabel(); }
   93 |
   94 |   //! replaces our current query with the value passed in
   95 |   void setQuery(QUERYATOM_QUERY *what) override {
   96 |     delete dp_query;
   97 |     dp_query = what;
   98 |   }
   99 |   //! returns our current query
  100 |   QUERYATOM_QUERY *getQuery() const override { return dp_query; }
  101 |
  102 |   //! expands our current query
  103 |   /*!
  104 |     \param what          the Queries::Query to be added. The ownership of
  105 |                          the query is passed to the current object, where it
  106 |                          might be deleted, so that the pointer should not be
  107 |                          used again in the calling code.
  108 |     \param how           the operator to be used in the expansion
  109 |     \param maintainOrder (optional) flags whether the relative order of
  110 |                          the queries needs to be maintained, if this is
  111 |                          false, the order is reversed
  112 |     <b>Notes:</b>
  113 |       - \c what should probably be constructed using one of the functions
  114 |          defined in QueryOps.h
  115 |       - the \c maintainOrder option can be useful because the combination
  116 |         operators short circuit when possible.
  117 |
  118 |   */
  119 |   void expandQuery(QUERYATOM_QUERY *what,
  120 |                    Queries::CompositeQueryType how = Queries::COMPOSITE_AND,
  121 |                    bool maintainOrder = true) override;
  122 |
  123 |   //! returns true if we match Atom \c what
  124 |   bool Match(Atom const *what) const override;
  125 |
  126 |   //! returns true if our query details match those of QueryAtom \c what
  127 |   bool QueryMatch(QueryAtom const *what) const;
  128 |
  129 |  private:
  130 |   QUERYATOM_QUERY *dp_query{nullptr};
  131 |
  132 | };  // end o' class
  133 |
  134 | namespace detail {
  135 | inline std::string qhelper(const Atom::QUERYATOM_QUERY *q, unsigned int depth) {
  136 |   std::string res = "";
  137 |   if (q) {
  138 |     for (unsigned int i = 0; i < depth; ++i) {
  139 |       res += "  ";
  140 |     }
  141 |     res += q->getFullDescription() + "\n";
  142 |     for (const auto &child :
  143 |          boost::make_iterator_range(q->beginChildren(), q->endChildren())) {
  144 |       res += qhelper(child.get(), depth + 1);
  145 |     }
  146 |   }
  147 |   return res;

Reach line at /src/rdkit/Code/GraphMol/QueryAtom.h:47 (observed count 449).


    1 | /* adler32.c -- compute the Adler-32 checksum of a data stream
    2 |  * Copyright (C) 1995-2011, 2016 Mark Adler
    3 |  * For conditions of distribution and use, see copyright notice in zlib.h
    4 |  */
    5 |
    6 | /* @(#) $Id$ */
    7 |
    8 | #include "zutil.h"
    9 |
   10 | #define BASE 65521U     /* largest prime smaller than 65536 */
   11 | #define NMAX 5552
   12 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
   13 |
   14 | #define DO1(buf,i)  {adler += (buf)[i]; sum2 += adler;}
   15 | #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
   16 | #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
   17 | #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
>  18 | #define DO16(buf)   DO8(buf,0); DO8(buf,8);
   19 |
   20 | /* use NO_DIVIDE if your processor does not do division in hardware --
   21 |    try it both ways to see which is faster */
   22 | #ifdef NO_DIVIDE
   23 | /* note that this assumes BASE is 65521, where 65536 % 65521 == 15
   24 |    (thank you to John Reiser for pointing this out) */
   25 | #  define CHOP(a) \
   26 |     do { \
   27 |         unsigned long tmp = a >> 16; \
   28 |         a &= 0xffffUL; \
   29 |         a += (tmp << 4) - tmp; \
   30 |     } while (0)
   31 | #  define MOD28(a) \
   32 |     do { \
   33 |         CHOP(a); \
   34 |         if (a >= BASE) a -= BASE; \
   35 |     } while (0)
   36 | #  define MOD(a) \
   37 |     do { \
   38 |         CHOP(a); \
   39 |         MOD28(a); \
   40 |     } while (0)
   41 | #  define MOD63(a) \
   42 |     do { /* this assumes a is not negative */ \
   43 |         z_off64_t tmp = a >> 32; \
   44 |         a &= 0xffffffffL; \
   45 |         a += (tmp << 8) - (tmp << 5) + tmp; \
   46 |         tmp = a >> 16; \
   47 |         a &= 0xffffL; \
   48 |         a += (tmp << 4) - tmp; \
   49 |         tmp = a >> 16; \
   50 |         a &= 0xffffL; \
   51 |         a += (tmp << 4) - tmp; \
   52 |         if (a >= BASE) a -= BASE; \
   53 |     } while (0)
   54 | #else
   55 | #  define MOD(a) a %= BASE
   56 | #  define MOD28(a) a %= BASE
   57 | #  define MOD63(a) a %= BASE
   58 | #endif
   59 |
   60 | /* ========================================================================= */
   61 | uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len) {
   62 |     unsigned long sum2;
   63 |     unsigned n;
   64 |
   65 |     /* split Adler-32 into component sums */
   66 |     sum2 = (adler >> 16) & 0xffff;
   67 |     adler &= 0xffff;
   68 |
   69 |     /* in case user likes doing a byte at a time, keep it fast */
   70 |     if (len == 1) {
   71 |         adler += buf[0];
   72 |         if (adler >= BASE)
   73 |             adler -= BASE;
   74 |         sum2 += adler;
   75 |         if (sum2 >= BASE)
   76 |             sum2 -= BASE;
   77 |         return adler | (sum2 << 16);
   78 |     }
   79 |
   80 |     /* initial Adler-32 value (deferred check for len == 1 speed) */
   81 |     if (buf == Z_NULL)
   82 |         return 1L;
   83 |
   84 |     /* in case short lengths are provided, keep it somewhat fast */
   85 |     if (len < 16) {
   86 |         while (len--) {
   87 |             adler += *buf++;
   88 |             sum2 += adler;
   89 |         }
   90 |         if (adler >= BASE)
   91 |             adler -= BASE;
   92 |         MOD28(sum2);            /* only added so many BASE's */
   93 |         return adler | (sum2 << 16);
   94 |     }
   95 |
   96 |     /* do length NMAX blocks -- requires just one modulo operation */
   97 |     while (len >= NMAX) {
   98 |         len -= NMAX;
   99 |         n = NMAX / 16;          /* NMAX is divisible by 16 */
  100 |         do {
  101 |             DO16(buf);          /* 16 sums unrolled */
  102 |             buf += 16;
  103 |         } while (--n);
  104 |         MOD(adler);
  105 |         MOD(sum2);
  106 |     }
  107 |
  108 |     /* do remaining bytes (less than NMAX, still just one modulo) */
  109 |     if (len) {                  /* avoid modulos if none remaining */
  110 |         while (len >= 16) {
  111 |             len -= 16;
  112 |             DO16(buf);
  113 |             buf += 16;
  114 |         }
  115 |         while (len--) {
  116 |             adler += *buf++;
  117 |             sum2 += adler;
  118 |         }

Reach line at /src/zlib/adler32.c:18 (observed count 355000000).