New Defects reported by Coverity Scan for digiKam

scan-admin-S5/EvlXga/RWk0Htik3J/[email protected] Sun, 26 Jul 2026 21:51:30 +0000 (UTC)
Newsgroups gmane.comp.kde.digikam.devel
Message-ID <[email protected]>
----==_mimepart_6a668161e92f5_895032cbc189f39a8936e
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

Please find the latest report on new defect(s) introduced to digiKam found with Coverity Scan.

130 new defect(s) introduced to digiKam found with Coverity Scan.
1 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent build analyzed by Coverity Scan.

New defect(s) Reported-by: Coverity Scan
Showing 20 of 130 defect(s)


** CID 1697260:       Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/deepseek32.cpp: 114           in llama_model_deepseek32::load_arch_tensors(llama_model_loader &)()


_____________________________________________________________________________________________
*** CID 1697260:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/deepseek32.cpp: 114             in llama_model_deepseek32::load_arch_tensors(llama_model_loader &)()
108     
109             // DSA indexer
110             layer.indexer_k_norm   = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   "weight", i), {hparams.indexer_head_size}, flags);
111             layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   "bias",   i), {hparams.indexer_head_size}, flags);
112             layer.indexer_proj     = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ,     "weight", i), {n_embd, hparams.indexer_n_head}, flags);
113             layer.indexer_attn_k   = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K,   "weight", i), {n_embd, hparams.indexer_head_size}, flags);
>>>     CID 1697260:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
>>>     Potentially overflowing expression "this->hparams.indexer_n_head * this->hparams.indexer_head_size" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "int64_t const" (64 bits, signed).
114             layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, "weight", i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags);
115             if (i < (int) hparams.n_layer_dense_lead) {
116                 layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd,   n_ff}, flags);
117                 layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), {  n_ff, n_embd}, flags);
118                 layer.ffn_up   = create_tensor(tn(LLM_TENSOR_FFN_UP,   "weight", i), {n_embd,   n_ff}, flags);
119             } else {

** CID 1697259:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1313           in ggml_row_size()


_____________________________________________________________________________________________
*** CID 1697259:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1313             in ggml_row_size()
1307         assert(type >= 0);
1308         assert(type < GGML_TYPE_COUNT);
1309         return type_traits[type].type_size;
1310     }
1311     
1312     size_t ggml_row_size(enum ggml_type type, int64_t ne) {
>>>     CID 1697259:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1313         assert(type >= 0);
1314         assert(type < GGML_TYPE_COUNT);
1315         assert(ne % ggml_blck_size(type) == 0);
1316         return ggml_type_size(type)*ne/ggml_blck_size(type);
1317     }
1318     

** CID 1697258:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1307           in ggml_type_size()


_____________________________________________________________________________________________
*** CID 1697258:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1307             in ggml_type_size()
1301         assert(type >= 0);
1302         assert(type < GGML_TYPE_COUNT);
1303         return type_traits[type].blck_size;
1304     }
1305     
1306     size_t ggml_type_size(enum ggml_type type) {
>>>     CID 1697258:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1307         assert(type >= 0);
1308         assert(type < GGML_TYPE_COUNT);
1309         return type_traits[type].type_size;
1310     }
1311     
1312     size_t ggml_row_size(enum ggml_type type, int64_t ne) {

** CID 1697257:       Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/glm-dsa.cpp: 108           in llama_model_glm_dsa::load_arch_tensors(llama_model_loader &)()


_____________________________________________________________________________________________
*** CID 1697257:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/glm-dsa.cpp: 108             in llama_model_glm_dsa::load_arch_tensors(llama_model_loader &)()
102     
103             // DSA indexer
104             layer.indexer_k_norm   = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   "weight", i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
105             layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   "bias",   i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
106             layer.indexer_proj     = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ,     "weight", i), {n_embd, hparams.indexer_n_head}, flags | TENSOR_NOT_REQUIRED);
107             layer.indexer_attn_k   = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K,   "weight", i), {n_embd, hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
>>>     CID 1697257:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
>>>     Potentially overflowing expression "this->hparams.indexer_n_head * this->hparams.indexer_head_size" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "int64_t const" (64 bits, signed).
108             layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, "weight", i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
109             if (i < (int) hparams.n_layer_dense_lead) {
110                 layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd,   n_ff}, flags);
111                 layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), {  n_ff, n_embd}, flags);
112                 layer.ffn_up   = create_tensor(tn(LLM_TENSOR_FFN_UP,   "weight", i), {n_embd,   n_ff}, flags);
113             } else {

** CID 1697256:       Null pointer dereferences  (FORWARD_NULL)


_____________________________________________________________________________________________
*** CID 1697256:         Null pointer dereferences  (FORWARD_NULL)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama.cpp: 389             in llama_model_load_from_file_impl(gguf_context *, void (*)(ggml_tensor *, void *), void *, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> &, _IO_FILE *, llama_model_params)()
383                     }
384                 }
385                 return true;
386             };
387         }
388     
>>>     CID 1697256:         Null pointer dereferences  (FORWARD_NULL)
>>>     Passing null pointer "metadata" to "llama_model_load", which dereferences it.
389         const auto [status, model] = llama_model_load(metadata, set_tensor_data, set_tensor_data_ud, path_model, splits, file, params);
390         GGML_ASSERT(status <= 0);
391         if (status < 0) {
392             if (status == -1) {
393                 LLAMA_LOG_ERROR("%s: failed to load model\n", __func__);
394             } else if (status == -2) {

** CID 1697255:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1326           in ggml_type_name()


_____________________________________________________________________________________________
*** CID 1697255:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1326             in ggml_type_name()
1320         assert(type >= 0);
1321         assert(type < GGML_TYPE_COUNT);
1322         return ((double)(type_traits[type].type_size))/type_traits[type].blck_size;
1323     }
1324     
1325     const char * ggml_type_name(enum ggml_type type) {
>>>     CID 1697255:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1326         assert(type >= 0);
1327         assert(type < GGML_TYPE_COUNT);
1328         return type_traits[type].type_name;
1329     }
1330     
1331     bool ggml_is_quantized(enum ggml_type type) {

** CID 1697254:       Integer handling issues  (INTEGER_OVERFLOW)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchllamabackend.cpp: 233           in Digikam::SearchLlamaWorker::slotDoInference(const QString &, int, float)()


_____________________________________________________________________________________________
*** CID 1697254:         Integer handling issues  (INTEGER_OVERFLOW)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchllamabackend.cpp: 233             in Digikam::SearchLlamaWorker::slotDoInference(const QString &, int, float)()
227     
228         llama_memory_clear(llama_get_memory(ctx), true);
229     
230         // 1. Tokenize the prompt
231         const QByteArray promptUtf8 = prompt.toUtf8();
232     
>>>     CID 1697254:         Integer handling issues  (INTEGER_OVERFLOW)
>>>     Expression "-llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)", where "llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)" is known to be equal to -2147483648, overflows the type of "-llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)", which is type "int32_t".
233         const int n_prompt = -llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(),
234                                              nullptr, 0, true, true);
235     
236         if (n_prompt <= 0)
237         {
238             Q_EMIT signalError(QLatin1String("Failed to tokenize the prompt."));

** CID 1697253:       Performance inefficiencies  (AUTO_CAUSES_COPY)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model.cpp: 2624           in llama_model_chat_template()


_____________________________________________________________________________________________
*** CID 1697253:         Performance inefficiencies  (AUTO_CAUSES_COPY)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model.cpp: 2624             in llama_model_chat_template()
2618     
2619     uint64_t llama_model_size(const llama_model * model) {
2620         return model->size();
2621     }
2622     
2623     const char * llama_model_chat_template(const llama_model * model, const char * name) {
>>>     CID 1697253:         Performance inefficiencies  (AUTO_CAUSES_COPY)
>>>     Using the "auto" keyword without an "&" causes the copy of an object of type "std::string".
2624         const auto key = name ? LLM_KV(model->arch, name)(LLM_KV_TOKENIZER_CHAT_TEMPLATE)
2625             : LLM_KV(model->arch)(LLM_KV_TOKENIZER_CHAT_TEMPLATE);
2626         const auto & it = model->gguf_kv.find(key);
2627         if (it == model->gguf_kv.end()) {
2628             // one-off fix for very popular models (so we are not flooded with issues)
2629             // do not extend this list unless absolutely necessary

** CID 1697252:         (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 54           in llama_model_gemma4::load_arch_tensors(llama_model_loader &)()
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 53           in llama_model_gemma4::load_arch_tensors(llama_model_loader &)()


_____________________________________________________________________________________________
*** CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 54             in llama_model_gemma4::load_arch_tensors(llama_model_loader &)()
48         }
49     
50         tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
51     
52         if (n_embd_per_layer > 0) {
53             per_layer_tok_embd   = create_tensor(tn(LLM_TENSOR_PER_LAYER_TOKEN_EMBD, "weight"),    {n_embd_per_layer * n_layer, n_vocab}, 0);
>>>     CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
>>>     Potentially overflowing expression "n_embd_per_layer * n_layer" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "int64_t const" (64 bits, signed).
54             per_layer_model_proj = create_tensor(tn(LLM_TENSOR_PER_LAYER_MODEL_PROJ, "weight", 0), {n_embd, n_embd_per_layer * n_layer}, 0);
55             per_layer_proj_norm  = create_tensor(tn(LLM_TENSOR_PER_LAYER_PROJ_NORM,  "weight", 0), {n_embd_per_layer}, 0);
56         }
57     
58         output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0);
59     
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 53             in llama_model_gemma4::load_arch_tensors(llama_model_loader &)()
47             output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, TENSOR_DUPLICATED);
48         }
49     
50         tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
51     
52         if (n_embd_per_layer > 0) {
>>>     CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
>>>     Potentially overflowing expression "n_embd_per_layer * n_layer" with type "unsigned int" (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type "int64_t const" (64 bits, signed).
53             per_layer_tok_embd   = create_tensor(tn(LLM_TENSOR_PER_LAYER_TOKEN_EMBD, "weight"),    {n_embd_per_layer * n_layer, n_vocab}, 0);
54             per_layer_model_proj = create_tensor(tn(LLM_TENSOR_PER_LAYER_MODEL_PROJ, "weight", 0), {n_embd, n_embd_per_layer * n_layer}, 0);
55             per_layer_proj_norm  = create_tensor(tn(LLM_TENSOR_PER_LAYER_PROJ_NORM,  "weight", 0), {n_embd_per_layer}, 0);
56         }
57     
58         output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0);

** CID 1697251:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 930           in ggml_get_type_traits()


_____________________________________________________________________________________________
*** CID 1697251:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 930             in ggml_get_type_traits()
924             .type_size                = 0,
925             .is_quantized             = false,
926         },
927     };
928     
929     const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type) {
>>>     CID 1697251:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
930         assert(type >= 0);
931         assert(type < GGML_TYPE_COUNT);
932         return &type_traits[type];
933     }
934     
935     //

** CID 1697250:       Control flow issues  (UNREACHABLE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp: 4039           in llamafile_sgemm()


_____________________________________________________________________________________________
*** CID 1697250:         Control flow issues  (UNREACHABLE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp: 4039             in llamafile_sgemm()
4033         }
4034     
4035         default:
4036             return false;
4037         }
4038     
>>>     CID 1697250:         Control flow issues  (UNREACHABLE)
>>>     This code cannot be reached: "(void)params;".
4039         (void)params;
4040         (void)m;
4041         (void)n;
4042         (void)k;
4043         (void)A;
4044         (void)lda;

** CID 1697249:       Null pointer dereferences  (NULL_RETURNS)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 181           in ggml_print_backtrace()


_____________________________________________________________________________________________
*** CID 1697249:         Null pointer dereferences  (NULL_RETURNS)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 181             in ggml_print_backtrace()
175     #endif
176     #if defined(__linux__)
177         FILE * f = fopen("/proc/self/status", "r");
178         size_t size = 0;
179         char * line = NULL;
180         ssize_t length = 0;
>>>     CID 1697249:         Null pointer dereferences  (NULL_RETURNS)
>>>     Dereferencing a pointer that might be "NULL" "f" when calling "getline". (The dereference is assumed on the basis of the "nonnull" parameter attribute.)
181         while ((length = getline(&line, &size, f)) > 0) {
182             if (!strncmp(line, "TracerPid:", sizeof("TracerPid:") - 1) &&
183                 (length != sizeof("TracerPid:\t0\n") - 1 || line[length - 2] != '0')) {
184                 // Already being debugged, and the breakpoint is the later abort()
185                 free(line);
186                 fclose(f);

** CID 1697248:       Performance inefficiencies  (PASS_BY_VALUE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchqueryengine.cpp: 123           in Digikam::SearchQueryEngine::slotInterpretQuery(const QString &, const QString &)::[lambda() (instance 1)]::operator ()() const()


_____________________________________________________________________________________________
*** CID 1697248:         Performance inefficiencies  (PASS_BY_VALUE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchqueryengine.cpp: 123             in Digikam::SearchQueryEngine::slotInterpretQuery(const QString &, const QString &)::[lambda() (instance 1)]::operator ()() const()
117         if (d->cache)
118         {
119             SearchQueryIntent cached;
120     
121             if (d->cache->lookup(d->normalizedQuery, &cached))
122             {
>>>     CID 1697248:         Performance inefficiencies  (PASS_BY_VALUE)
>>>     Capturing variable "cached" of type "Digikam::SearchQueryIntent" (size 152 bytes) by value, which exceeds the low threshold of 128 bytes.
123                 QTimer::singleShot(0, this, [this, cached]()
124                     {
125                         Q_EMIT signalIntentReady(cached);
126                     }
127                 );
128     

** CID 1697247:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1320           in ggml_type_sizef()


_____________________________________________________________________________________________
*** CID 1697247:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1320             in ggml_type_sizef()
1314         assert(type < GGML_TYPE_COUNT);
1315         assert(ne % ggml_blck_size(type) == 0);
1316         return ggml_type_size(type)*ne/ggml_blck_size(type);
1317     }
1318     
1319     double ggml_type_sizef(enum ggml_type type) {
>>>     CID 1697247:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1320         assert(type >= 0);
1321         assert(type < GGML_TYPE_COUNT);
1322         return ((double)(type_traits[type].type_size))/type_traits[type].blck_size;
1323     }
1324     
1325     const char * ggml_type_name(enum ggml_type type) {

** CID 1697246:       Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-kv-cache-dsv4.cpp: 148           in dsv4_build_raw_write_ubatch(const llama_ubatch &)()


_____________________________________________________________________________________________
*** CID 1697246:         Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-kv-cache-dsv4.cpp: 148             in dsv4_build_raw_write_ubatch(const llama_ubatch &)()
142             /*.pos          =*/ data->pos.data(),
143             /*.n_seq_id     =*/ data->n_seq_id.data(),
144             /*.seq_id       =*/ data->seq_id.data(),
145             /*.seq_id_unq   =*/ data->seq_id_unq.data(),
146             /*.seq_idx      =*/ data->seq_idx.data(),
147             /*.output       =*/ data->output.data(),
>>>     CID 1697246:         Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
>>>     "data" is copied in call to copy constructor for class "std::shared_ptr<llama_ubatch::data_t>", when it could be moved instead.
148             /*.data         =*/ data,
149         };
150     
151         return res;
152     }
153     

** CID 1697245:       API usage errors  (LOCK)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-quant.cpp: 747           in llama_tensor_quantize_impl(ggml_type, const float *, void *, long, long, long, const float *, std::vector<std::thread, std::allocator<std::thread>> &, int)::[lambda() (instance 1)]::operator ()() const()


_____________________________________________________________________________________________
*** CID 1697245:         API usage errors  (LOCK)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-quant.cpp: 747             in llama_tensor_quantize_impl(ggml_type, const float *, void *, long, long, long, const float *, std::vector<std::thread, std::allocator<std::thread>> &, int)::[lambda() (instance 1)]::operator ()() const()
741                 // validate the quantized data
742                 const size_t row_size  = ggml_row_size(new_type, n_per_row);
743                 void * this_data = (char *) new_data + first_row * row_size;
744                 if (!ggml_validate_row_data(new_type, this_data, this_size)) {
745                     std::unique_lock<std::mutex> lock(mutex);
746                     valid = false;
>>>     CID 1697245:         API usage errors  (LOCK)
>>>     "~unique_lock" unlocks "lock" while it is unlocked. [Note: The source code implementation of the function has been overridden by a builtin model.]
747                     break;
748                 }
749             }
750         };
751         for (int it = 0; it < nthread - 1; ++it) {
752             workers.emplace_back(compute);

** CID 1697244:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1301           in ggml_blck_size()


_____________________________________________________________________________________________
*** CID 1697244:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1301             in ggml_blck_size()
1295     
1296     size_t ggml_nbytes_pad(const struct ggml_tensor * tensor) {
1297         return GGML_PAD(ggml_nbytes(tensor), GGML_MEM_ALIGN);
1298     }
1299     
1300     int64_t ggml_blck_size(enum ggml_type type) {
>>>     CID 1697244:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1301         assert(type >= 0);
1302         assert(type < GGML_TYPE_COUNT);
1303         return type_traits[type].blck_size;
1304     }
1305     
1306     size_t ggml_type_size(enum ggml_type type) {

** CID 1697243:         (CHECKED_RETURN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 57           in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const()
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 58           in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const()


_____________________________________________________________________________________________
*** CID 1697243:           (CHECKED_RETURN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 57             in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const()
51     
52         // custom comparator to sort weights more nicely by layer
53         struct weight_name_comparer {
54             bool operator()(const std::string & a, const std::string & b) const {
55                 int a_layer = -1;
56                 int b_layer = -1;
>>>     CID 1697243:           (CHECKED_RETURN)
>>>     Calling "sscanf" without checking return value (as is done elsewhere 32 out of 40 times).
57                 sscanf(a.c_str(), "blk.%d.", &a_layer);
58                 sscanf(b.c_str(), "blk.%d.", &b_layer);
59                 if (a_layer != b_layer) {
60                     return a_layer < b_layer;
61                 }
62                 return a < b;
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 58             in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &, const std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> &) const()
52         // custom comparator to sort weights more nicely by layer
53         struct weight_name_comparer {
54             bool operator()(const std::string & a, const std::string & b) const {
55                 int a_layer = -1;
56                 int b_layer = -1;
57                 sscanf(a.c_str(), "blk.%d.", &a_layer);
>>>     CID 1697243:           (CHECKED_RETURN)
>>>     Calling "sscanf" without checking return value (as is done elsewhere 32 out of 40 times).
58                 sscanf(b.c_str(), "blk.%d.", &b_layer);
59                 if (a_layer != b_layer) {
60                     return a_layer < b_layer;
61                 }
62                 return a < b;
63             }

** CID 1697242:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1332           in ggml_is_quantized()


_____________________________________________________________________________________________
*** CID 1697242:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1332             in ggml_is_quantized()
1326         assert(type >= 0);
1327         assert(type < GGML_TYPE_COUNT);
1328         return type_traits[type].type_name;
1329     }
1330     
1331     bool ggml_is_quantized(enum ggml_type type) {
>>>     CID 1697242:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
>>>     "type >= 0" is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1332         assert(type >= 0);
1333         assert(type < GGML_TYPE_COUNT);
1334         return type_traits[type].is_quantized;
1335     }
1336     
1337     const char * ggml_op_name(enum ggml_op op) {

** CID 1697241:       Incorrect expression  (COPY_PASTE_ERROR)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-backend-meta.cpp: 586           in ggml_backend_meta_get_split_state(ggml_backend_meta_simple_tensor_container &, const ggml_tensor *, bool)::[lambda(const std::vector<ggml_backend_meta_split_state, std::allocator<ggml_backend_meta_split_state>> &) (instance 4)]::operator ()(const std::vector<ggml_backend_meta_split_state, std::allocator<ggml_backend_meta_split_state>> &) const()


_____________________________________________________________________________________________
*** CID 1697241:         Incorrect expression  (COPY_PASTE_ERROR)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-backend-meta.cpp: 586             in ggml_backend_meta_get_split_state(ggml_backend_meta_simple_tensor_container &, const ggml_tensor *, bool)::[lambda(const std::vector<ggml_backend_meta_split_state, std::allocator<ggml_backend_meta_split_state>> &) (instance 4)]::operator ()(const std::vector<ggml_backend_meta_split_state, std::allocator<ggml_backend_meta_split_state>> &) const()
580                 ggml_backend_meta_split_state ret = src_ss[0];
581                 ret.axis = GGML_BACKEND_SPLIT_AXIS_0;
582                 ret.nr[0] = 1;
583                 ret.n_segments = 1;
584                 return ret;
585             }
>>>     CID 1697241:         Incorrect expression  (COPY_PASTE_ERROR)
>>>     "GGML_BACKEND_SPLIT_AXIS_MIRRORED" looks like a copy-paste error.
586             if (src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_1 && src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED) {
587                 return src_ss[1];
588             }
589             if (src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_0 && src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_0) {
590                 GGML_ASSERT(split_states_equal(src_ss[0], src_ss[1]));
591                 return {assume_sync ? GGML_BACKEND_SPLIT_AXIS_MIRRORED : GGML_BACKEND_SPLIT_AXIS_PARTIAL, {0}, {1}, 1};


________________________________________________________________________________________________________
To view the defects in Coverity Scan visit, https://scan.coverity.com/projects/digikam?tab=overview


----==_mimepart_6a668161e92f5_895032cbc189f39a8936e
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>New Defects Reported - digiKam</title>
  <style>
    body { font-family: Arial, sans-serif; color: #222; line-height: 1.6; }
    .button {
      display: inline-block;
      padding: 10px 20px;
      margin: 20px 0;
      font-size: 16px;
      color: #fff !important;
      background-color: #0056b3;
      text-decoration: none;
      border-radius: 5px;
    }
    pre {
      background: #f8f9fa;
      padding: 10px;
      border-radius: 5px;
      font-size: 14px;
      overflow-x: auto;
    }
  </style>
</head>
<body>
  <p>Hi,</p>

  <p>
    Please find the latest report on new defect(s) introduced to <strong>digiKam</strong>
     found with Coverity Scan.
  </p>  

  <ul>
    <li><strong>New Defects Found:</strong> 130</li>
      <li>
        1 defect(s), reported by Coverity Scan earlier, were marked fixed in the recent build analyzed by Coverity Scan.
      </li>
    <li><strong>Defects Shown:</strong> Showing 20 of 130 defect(s)</li>
  </ul>

  <h3>Defect Details</h3>
  <pre>
** CID 1697260:       Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/deepseek32.cpp: 114           in llama_model_deepseek32::load_arch_tensors(llama_model_loader &amp;)()


_____________________________________________________________________________________________
*** CID 1697260:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/deepseek32.cpp: 114             in llama_model_deepseek32::load_arch_tensors(llama_model_loader &amp;)()
108     
109             // DSA indexer
110             layer.indexer_k_norm   = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   &quot;weight&quot;, i), {hparams.indexer_head_size}, flags);
111             layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   &quot;bias&quot;,   i), {hparams.indexer_head_size}, flags);
112             layer.indexer_proj     = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ,     &quot;weight&quot;, i), {n_embd, hparams.indexer_n_head}, flags);
113             layer.indexer_attn_k   = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K,   &quot;weight&quot;, i), {n_embd, hparams.indexer_head_size}, flags);
&gt;&gt;&gt;     CID 1697260:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
&gt;&gt;&gt;     Potentially overflowing expression &quot;this-&gt;hparams.indexer_n_head * this-&gt;hparams.indexer_head_size&quot; with type &quot;unsigned int&quot; (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type &quot;int64_t const&quot; (64 bits, signed).
114             layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, &quot;weight&quot;, i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags);
115             if (i &lt; (int) hparams.n_layer_dense_lead) {
116                 layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, &quot;weight&quot;, i), {n_embd,   n_ff}, flags);
117                 layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, &quot;weight&quot;, i), {  n_ff, n_embd}, flags);
118                 layer.ffn_up   = create_tensor(tn(LLM_TENSOR_FFN_UP,   &quot;weight&quot;, i), {n_embd,   n_ff}, flags);
119             } else {

** CID 1697259:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1313           in ggml_row_size()


_____________________________________________________________________________________________
*** CID 1697259:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1313             in ggml_row_size()
1307         assert(type &gt;= 0);
1308         assert(type &lt; GGML_TYPE_COUNT);
1309         return type_traits[type].type_size;
1310     }
1311     
1312     size_t ggml_row_size(enum ggml_type type, int64_t ne) {
&gt;&gt;&gt;     CID 1697259:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1313         assert(type &gt;= 0);
1314         assert(type &lt; GGML_TYPE_COUNT);
1315         assert(ne % ggml_blck_size(type) == 0);
1316         return ggml_type_size(type)*ne/ggml_blck_size(type);
1317     }
1318     

** CID 1697258:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1307           in ggml_type_size()


_____________________________________________________________________________________________
*** CID 1697258:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1307             in ggml_type_size()
1301         assert(type &gt;= 0);
1302         assert(type &lt; GGML_TYPE_COUNT);
1303         return type_traits[type].blck_size;
1304     }
1305     
1306     size_t ggml_type_size(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697258:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1307         assert(type &gt;= 0);
1308         assert(type &lt; GGML_TYPE_COUNT);
1309         return type_traits[type].type_size;
1310     }
1311     
1312     size_t ggml_row_size(enum ggml_type type, int64_t ne) {

** CID 1697257:       Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/glm-dsa.cpp: 108           in llama_model_glm_dsa::load_arch_tensors(llama_model_loader &amp;)()


_____________________________________________________________________________________________
*** CID 1697257:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/glm-dsa.cpp: 108             in llama_model_glm_dsa::load_arch_tensors(llama_model_loader &amp;)()
102     
103             // DSA indexer
104             layer.indexer_k_norm   = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   &quot;weight&quot;, i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
105             layer.indexer_k_norm_b = create_tensor(tn(LLM_TENSOR_INDEXER_K_NORM,   &quot;bias&quot;,   i), {hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
106             layer.indexer_proj     = create_tensor(tn(LLM_TENSOR_INDEXER_PROJ,     &quot;weight&quot;, i), {n_embd, hparams.indexer_n_head}, flags | TENSOR_NOT_REQUIRED);
107             layer.indexer_attn_k   = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_K,   &quot;weight&quot;, i), {n_embd, hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
&gt;&gt;&gt;     CID 1697257:         Integer handling issues  (OVERFLOW_BEFORE_WIDEN)
&gt;&gt;&gt;     Potentially overflowing expression &quot;this-&gt;hparams.indexer_n_head * this-&gt;hparams.indexer_head_size&quot; with type &quot;unsigned int&quot; (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type &quot;int64_t const&quot; (64 bits, signed).
108             layer.indexer_attn_q_b = create_tensor(tn(LLM_TENSOR_INDEXER_ATTN_Q_B, &quot;weight&quot;, i), {q_lora_rank, hparams.indexer_n_head * hparams.indexer_head_size}, flags | TENSOR_NOT_REQUIRED);
109             if (i &lt; (int) hparams.n_layer_dense_lead) {
110                 layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, &quot;weight&quot;, i), {n_embd,   n_ff}, flags);
111                 layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, &quot;weight&quot;, i), {  n_ff, n_embd}, flags);
112                 layer.ffn_up   = create_tensor(tn(LLM_TENSOR_FFN_UP,   &quot;weight&quot;, i), {n_embd,   n_ff}, flags);
113             } else {

** CID 1697256:       Null pointer dereferences  (FORWARD_NULL)


_____________________________________________________________________________________________
*** CID 1697256:         Null pointer dereferences  (FORWARD_NULL)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama.cpp: 389             in llama_model_load_from_file_impl(gguf_context *, void (*)(ggml_tensor *, void *), void *, const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;, std::vector&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;, std::allocator&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;&gt;&gt; &amp;, _IO_FILE *, llama_model_params)()
383                     }
384                 }
385                 return true;
386             };
387         }
388     
&gt;&gt;&gt;     CID 1697256:         Null pointer dereferences  (FORWARD_NULL)
&gt;&gt;&gt;     Passing null pointer &quot;metadata&quot; to &quot;llama_model_load&quot;, which dereferences it.
389         const auto [status, model] = llama_model_load(metadata, set_tensor_data, set_tensor_data_ud, path_model, splits, file, params);
390         GGML_ASSERT(status &lt;= 0);
391         if (status &lt; 0) {
392             if (status == -1) {
393                 LLAMA_LOG_ERROR(&quot;%s: failed to load model\n&quot;, __func__);
394             } else if (status == -2) {

** CID 1697255:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1326           in ggml_type_name()


_____________________________________________________________________________________________
*** CID 1697255:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1326             in ggml_type_name()
1320         assert(type &gt;= 0);
1321         assert(type &lt; GGML_TYPE_COUNT);
1322         return ((double)(type_traits[type].type_size))/type_traits[type].blck_size;
1323     }
1324     
1325     const char * ggml_type_name(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697255:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1326         assert(type &gt;= 0);
1327         assert(type &lt; GGML_TYPE_COUNT);
1328         return type_traits[type].type_name;
1329     }
1330     
1331     bool ggml_is_quantized(enum ggml_type type) {

** CID 1697254:       Integer handling issues  (INTEGER_OVERFLOW)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchllamabackend.cpp: 233           in Digikam::SearchLlamaWorker::slotDoInference(const QString &amp;, int, float)()


_____________________________________________________________________________________________
*** CID 1697254:         Integer handling issues  (INTEGER_OVERFLOW)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchllamabackend.cpp: 233             in Digikam::SearchLlamaWorker::slotDoInference(const QString &amp;, int, float)()
227     
228         llama_memory_clear(llama_get_memory(ctx), true);
229     
230         // 1. Tokenize the prompt
231         const QByteArray promptUtf8 = prompt.toUtf8();
232     
&gt;&gt;&gt;     CID 1697254:         Integer handling issues  (INTEGER_OVERFLOW)
&gt;&gt;&gt;     Expression &quot;-llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)&quot;, where &quot;llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)&quot; is known to be equal to -2147483648, overflows the type of &quot;-llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(), NULL, 0, true, true)&quot;, which is type &quot;int32_t&quot;.
233         const int n_prompt = -llama_tokenize(vocab, promptUtf8.constData(), promptUtf8.size(),
234                                              nullptr, 0, true, true);
235     
236         if (n_prompt &lt;= 0)
237         {
238             Q_EMIT signalError(QLatin1String(&quot;Failed to tokenize the prompt.&quot;));

** CID 1697253:       Performance inefficiencies  (AUTO_CAUSES_COPY)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model.cpp: 2624           in llama_model_chat_template()


_____________________________________________________________________________________________
*** CID 1697253:         Performance inefficiencies  (AUTO_CAUSES_COPY)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model.cpp: 2624             in llama_model_chat_template()
2618     
2619     uint64_t llama_model_size(const llama_model * model) {
2620         return model-&gt;size();
2621     }
2622     
2623     const char * llama_model_chat_template(const llama_model * model, const char * name) {
&gt;&gt;&gt;     CID 1697253:         Performance inefficiencies  (AUTO_CAUSES_COPY)
&gt;&gt;&gt;     Using the &quot;auto&quot; keyword without an &quot;&amp;&quot; causes the copy of an object of type &quot;std::string&quot;.
2624         const auto key = name ? LLM_KV(model-&gt;arch, name)(LLM_KV_TOKENIZER_CHAT_TEMPLATE)
2625             : LLM_KV(model-&gt;arch)(LLM_KV_TOKENIZER_CHAT_TEMPLATE);
2626         const auto &amp; it = model-&gt;gguf_kv.find(key);
2627         if (it == model-&gt;gguf_kv.end()) {
2628             // one-off fix for very popular models (so we are not flooded with issues)
2629             // do not extend this list unless absolutely necessary

** CID 1697252:         (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 54           in llama_model_gemma4::load_arch_tensors(llama_model_loader &amp;)()
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 53           in llama_model_gemma4::load_arch_tensors(llama_model_loader &amp;)()


_____________________________________________________________________________________________
*** CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 54             in llama_model_gemma4::load_arch_tensors(llama_model_loader &amp;)()
48         }
49     
50         tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, &quot;weight&quot;), {n_embd, n_vocab}, 0);
51     
52         if (n_embd_per_layer &gt; 0) {
53             per_layer_tok_embd   = create_tensor(tn(LLM_TENSOR_PER_LAYER_TOKEN_EMBD, &quot;weight&quot;),    {n_embd_per_layer * n_layer, n_vocab}, 0);
&gt;&gt;&gt;     CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
&gt;&gt;&gt;     Potentially overflowing expression &quot;n_embd_per_layer * n_layer&quot; with type &quot;unsigned int&quot; (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type &quot;int64_t const&quot; (64 bits, signed).
54             per_layer_model_proj = create_tensor(tn(LLM_TENSOR_PER_LAYER_MODEL_PROJ, &quot;weight&quot;, 0), {n_embd, n_embd_per_layer * n_layer}, 0);
55             per_layer_proj_norm  = create_tensor(tn(LLM_TENSOR_PER_LAYER_PROJ_NORM,  &quot;weight&quot;, 0), {n_embd_per_layer}, 0);
56         }
57     
58         output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, &quot;weight&quot;), {n_embd}, 0);
59     
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/models/gemma4.cpp: 53             in llama_model_gemma4::load_arch_tensors(llama_model_loader &amp;)()
47             output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, &quot;weight&quot;), {n_embd, n_vocab}, TENSOR_DUPLICATED);
48         }
49     
50         tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, &quot;weight&quot;), {n_embd, n_vocab}, 0);
51     
52         if (n_embd_per_layer &gt; 0) {
&gt;&gt;&gt;     CID 1697252:           (OVERFLOW_BEFORE_WIDEN)
&gt;&gt;&gt;     Potentially overflowing expression &quot;n_embd_per_layer * n_layer&quot; with type &quot;unsigned int&quot; (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type &quot;int64_t const&quot; (64 bits, signed).
53             per_layer_tok_embd   = create_tensor(tn(LLM_TENSOR_PER_LAYER_TOKEN_EMBD, &quot;weight&quot;),    {n_embd_per_layer * n_layer, n_vocab}, 0);
54             per_layer_model_proj = create_tensor(tn(LLM_TENSOR_PER_LAYER_MODEL_PROJ, &quot;weight&quot;, 0), {n_embd, n_embd_per_layer * n_layer}, 0);
55             per_layer_proj_norm  = create_tensor(tn(LLM_TENSOR_PER_LAYER_PROJ_NORM,  &quot;weight&quot;, 0), {n_embd_per_layer}, 0);
56         }
57     
58         output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, &quot;weight&quot;), {n_embd}, 0);

** CID 1697251:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 930           in ggml_get_type_traits()


_____________________________________________________________________________________________
*** CID 1697251:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 930             in ggml_get_type_traits()
924             .type_size                = 0,
925             .is_quantized             = false,
926         },
927     };
928     
929     const struct ggml_type_traits * ggml_get_type_traits(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697251:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
930         assert(type &gt;= 0);
931         assert(type &lt; GGML_TYPE_COUNT);
932         return &amp;type_traits[type];
933     }
934     
935     //

** CID 1697250:       Control flow issues  (UNREACHABLE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp: 4039           in llamafile_sgemm()


_____________________________________________________________________________________________
*** CID 1697250:         Control flow issues  (UNREACHABLE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp: 4039             in llamafile_sgemm()
4033         }
4034     
4035         default:
4036             return false;
4037         }
4038     
&gt;&gt;&gt;     CID 1697250:         Control flow issues  (UNREACHABLE)
&gt;&gt;&gt;     This code cannot be reached: &quot;(void)params;&quot;.
4039         (void)params;
4040         (void)m;
4041         (void)n;
4042         (void)k;
4043         (void)A;
4044         (void)lda;

** CID 1697249:       Null pointer dereferences  (NULL_RETURNS)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 181           in ggml_print_backtrace()


_____________________________________________________________________________________________
*** CID 1697249:         Null pointer dereferences  (NULL_RETURNS)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 181             in ggml_print_backtrace()
175     #endif
176     #if defined(__linux__)
177         FILE * f = fopen(&quot;/proc/self/status&quot;, &quot;r&quot;);
178         size_t size = 0;
179         char * line = NULL;
180         ssize_t length = 0;
&gt;&gt;&gt;     CID 1697249:         Null pointer dereferences  (NULL_RETURNS)
&gt;&gt;&gt;     Dereferencing a pointer that might be &quot;NULL&quot; &quot;f&quot; when calling &quot;getline&quot;. (The dereference is assumed on the basis of the &quot;nonnull&quot; parameter attribute.)
181         while ((length = getline(&amp;line, &amp;size, f)) &gt; 0) {
182             if (!strncmp(line, &quot;TracerPid:&quot;, sizeof(&quot;TracerPid:&quot;) - 1) &amp;&amp;
183                 (length != sizeof(&quot;TracerPid:\t0\n&quot;) - 1 || line[length - 2] != &#39;0&#39;)) {
184                 // Already being debugged, and the breakpoint is the later abort()
185                 free(line);
186                 fclose(f);

** CID 1697248:       Performance inefficiencies  (PASS_BY_VALUE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchqueryengine.cpp: 123           in Digikam::SearchQueryEngine::slotInterpretQuery(const QString &amp;, const QString &amp;)::[lambda() (instance 1)]::operator ()() const()


_____________________________________________________________________________________________
*** CID 1697248:         Performance inefficiencies  (PASS_BY_VALUE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/nlsearch/searchqueryengine.cpp: 123             in Digikam::SearchQueryEngine::slotInterpretQuery(const QString &amp;, const QString &amp;)::[lambda() (instance 1)]::operator ()() const()
117         if (d-&gt;cache)
118         {
119             SearchQueryIntent cached;
120     
121             if (d-&gt;cache-&gt;lookup(d-&gt;normalizedQuery, &amp;cached))
122             {
&gt;&gt;&gt;     CID 1697248:         Performance inefficiencies  (PASS_BY_VALUE)
&gt;&gt;&gt;     Capturing variable &quot;cached&quot; of type &quot;Digikam::SearchQueryIntent&quot; (size 152 bytes) by value, which exceeds the low threshold of 128 bytes.
123                 QTimer::singleShot(0, this, [this, cached]()
124                     {
125                         Q_EMIT signalIntentReady(cached);
126                     }
127                 );
128     

** CID 1697247:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1320           in ggml_type_sizef()


_____________________________________________________________________________________________
*** CID 1697247:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1320             in ggml_type_sizef()
1314         assert(type &lt; GGML_TYPE_COUNT);
1315         assert(ne % ggml_blck_size(type) == 0);
1316         return ggml_type_size(type)*ne/ggml_blck_size(type);
1317     }
1318     
1319     double ggml_type_sizef(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697247:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1320         assert(type &gt;= 0);
1321         assert(type &lt; GGML_TYPE_COUNT);
1322         return ((double)(type_traits[type].type_size))/type_traits[type].blck_size;
1323     }
1324     
1325     const char * ggml_type_name(enum ggml_type type) {

** CID 1697246:       Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-kv-cache-dsv4.cpp: 148           in dsv4_build_raw_write_ubatch(const llama_ubatch &amp;)()


_____________________________________________________________________________________________
*** CID 1697246:         Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-kv-cache-dsv4.cpp: 148             in dsv4_build_raw_write_ubatch(const llama_ubatch &amp;)()
142             /*.pos          =*/ data-&gt;pos.data(),
143             /*.n_seq_id     =*/ data-&gt;n_seq_id.data(),
144             /*.seq_id       =*/ data-&gt;seq_id.data(),
145             /*.seq_id_unq   =*/ data-&gt;seq_id_unq.data(),
146             /*.seq_idx      =*/ data-&gt;seq_idx.data(),
147             /*.output       =*/ data-&gt;output.data(),
&gt;&gt;&gt;     CID 1697246:         Performance inefficiencies  (COPY_INSTEAD_OF_MOVE)
&gt;&gt;&gt;     &quot;data&quot; is copied in call to copy constructor for class &quot;std::shared_ptr&lt;llama_ubatch::data_t&gt;&quot;, when it could be moved instead.
148             /*.data         =*/ data,
149         };
150     
151         return res;
152     }
153     

** CID 1697245:       API usage errors  (LOCK)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-quant.cpp: 747           in llama_tensor_quantize_impl(ggml_type, const float *, void *, long, long, long, const float *, std::vector&lt;std::thread, std::allocator&lt;std::thread&gt;&gt; &amp;, int)::[lambda() (instance 1)]::operator ()() const()


_____________________________________________________________________________________________
*** CID 1697245:         API usage errors  (LOCK)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-quant.cpp: 747             in llama_tensor_quantize_impl(ggml_type, const float *, void *, long, long, long, const float *, std::vector&lt;std::thread, std::allocator&lt;std::thread&gt;&gt; &amp;, int)::[lambda() (instance 1)]::operator ()() const()
741                 // validate the quantized data
742                 const size_t row_size  = ggml_row_size(new_type, n_per_row);
743                 void * this_data = (char *) new_data + first_row * row_size;
744                 if (!ggml_validate_row_data(new_type, this_data, this_size)) {
745                     std::unique_lock&lt;std::mutex&gt; lock(mutex);
746                     valid = false;
&gt;&gt;&gt;     CID 1697245:         API usage errors  (LOCK)
&gt;&gt;&gt;     &quot;~unique_lock&quot; unlocks &quot;lock&quot; while it is unlocked. [Note: The source code implementation of the function has been overridden by a builtin model.]
747                     break;
748                 }
749             }
750         };
751         for (int it = 0; it &lt; nthread - 1; ++it) {
752             workers.emplace_back(compute);

** CID 1697244:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1301           in ggml_blck_size()


_____________________________________________________________________________________________
*** CID 1697244:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1301             in ggml_blck_size()
1295     
1296     size_t ggml_nbytes_pad(const struct ggml_tensor * tensor) {
1297         return GGML_PAD(ggml_nbytes(tensor), GGML_MEM_ALIGN);
1298     }
1299     
1300     int64_t ggml_blck_size(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697244:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1301         assert(type &gt;= 0);
1302         assert(type &lt; GGML_TYPE_COUNT);
1303         return type_traits[type].blck_size;
1304     }
1305     
1306     size_t ggml_type_size(enum ggml_type type) {

** CID 1697243:         (CHECKED_RETURN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 57           in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;, const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;) const()
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 58           in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;, const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;) const()


_____________________________________________________________________________________________
*** CID 1697243:           (CHECKED_RETURN)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 57             in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;, const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;) const()
51     
52         // custom comparator to sort weights more nicely by layer
53         struct weight_name_comparer {
54             bool operator()(const std::string &amp; a, const std::string &amp; b) const {
55                 int a_layer = -1;
56                 int b_layer = -1;
&gt;&gt;&gt;     CID 1697243:           (CHECKED_RETURN)
&gt;&gt;&gt;     Calling &quot;sscanf&quot; without checking return value (as is done elsewhere 32 out of 40 times).
57                 sscanf(a.c_str(), &quot;blk.%d.&quot;, &amp;a_layer);
58                 sscanf(b.c_str(), &quot;blk.%d.&quot;, &amp;b_layer);
59                 if (a_layer != b_layer) {
60                     return a_layer &lt; b_layer;
61                 }
62                 return a &lt; b;
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/src/llama-model-loader.h: 58             in llama_model_loader::weight_name_comparer::operator ()(const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;, const std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; &amp;) const()
52         // custom comparator to sort weights more nicely by layer
53         struct weight_name_comparer {
54             bool operator()(const std::string &amp; a, const std::string &amp; b) const {
55                 int a_layer = -1;
56                 int b_layer = -1;
57                 sscanf(a.c_str(), &quot;blk.%d.&quot;, &amp;a_layer);
&gt;&gt;&gt;     CID 1697243:           (CHECKED_RETURN)
&gt;&gt;&gt;     Calling &quot;sscanf&quot; without checking return value (as is done elsewhere 32 out of 40 times).
58                 sscanf(b.c_str(), &quot;blk.%d.&quot;, &amp;b_layer);
59                 if (a_layer != b_layer) {
60                     return a_layer &lt; b_layer;
61                 }
62                 return a &lt; b;
63             }

** CID 1697242:       Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1332           in ggml_is_quantized()


_____________________________________________________________________________________________
*** CID 1697242:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml.c: 1332             in ggml_is_quantized()
1326         assert(type &gt;= 0);
1327         assert(type &lt; GGML_TYPE_COUNT);
1328         return type_traits[type].type_name;
1329     }
1330     
1331     bool ggml_is_quantized(enum ggml_type type) {
&gt;&gt;&gt;     CID 1697242:         Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
&gt;&gt;&gt;     &quot;type &gt;= 0&quot; is always true regardless of the values of its operands. This occurs when converting to bool for an argument to a function call.
1332         assert(type &gt;= 0);
1333         assert(type &lt; GGML_TYPE_COUNT);
1334         return type_traits[type].is_quantized;
1335     }
1336     
1337     const char * ggml_op_name(enum ggml_op op) {

** CID 1697241:       Incorrect expression  (COPY_PASTE_ERROR)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-backend-meta.cpp: 586           in ggml_backend_meta_get_split_state(ggml_backend_meta_simple_tensor_container &amp;, const ggml_tensor *, bool)::[lambda(const std::vector&lt;ggml_backend_meta_split_state, std::allocator&lt;ggml_backend_meta_split_state&gt;&gt; &amp;) (instance 4)]::operator ()(const std::vector&lt;ggml_backend_meta_split_state, std::allocator&lt;ggml_backend_meta_split_state&gt;&gt; &amp;) const()


_____________________________________________________________________________________________
*** CID 1697241:         Incorrect expression  (COPY_PASTE_ERROR)
/home/gilles/devel/GIT/DK.llm/core/utilities/searchwindow/thirdparty/llama.cpp/ggml/src/ggml-backend-meta.cpp: 586             in ggml_backend_meta_get_split_state(ggml_backend_meta_simple_tensor_container &amp;, const ggml_tensor *, bool)::[lambda(const std::vector&lt;ggml_backend_meta_split_state, std::allocator&lt;ggml_backend_meta_split_state&gt;&gt; &amp;) (instance 4)]::operator ()(const std::vector&lt;ggml_backend_meta_split_state, std::allocator&lt;ggml_backend_meta_split_state&gt;&gt; &amp;) const()
580                 ggml_backend_meta_split_state ret = src_ss[0];
581                 ret.axis = GGML_BACKEND_SPLIT_AXIS_0;
582                 ret.nr[0] = 1;
583                 ret.n_segments = 1;
584                 return ret;
585             }
&gt;&gt;&gt;     CID 1697241:         Incorrect expression  (COPY_PASTE_ERROR)
&gt;&gt;&gt;     &quot;GGML_BACKEND_SPLIT_AXIS_MIRRORED&quot; looks like a copy-paste error.
586             if (src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_1 &amp;&amp; src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED) {
587                 return src_ss[1];
588             }
589             if (src_ss[0].axis == GGML_BACKEND_SPLIT_AXIS_0 &amp;&amp; src_ss[1].axis == GGML_BACKEND_SPLIT_AXIS_0) {
590                 GGML_ASSERT(split_states_equal(src_ss[0], src_ss[1]));
591                 return {assume_sync ? GGML_BACKEND_SPLIT_AXIS_MIRRORED : GGML_BACKEND_SPLIT_AXIS_PARTIAL, {0}, {1}, 1};

  </pre>

  <p>
    <a href="https://scan.coverity.com/projects/digikam?tab=overview" class="button">View Defects in Coverity Scan</a>
  </p>

  <p>Best regards,</p>
  <p>The Coverity Scan Admin Team</p>
  <img class="logo" width="140" src="https://scan.coverity.com/assets/BlackDuckLogo-6697adc63e07340464201a2ad534d3d3e44f95d36edda20b140440d34f05372f.svg" />
</body>
</html>
----==_mimepart_6a668161e92f5_895032cbc189f39a8936e--