diff --git a/mesh/model.c b/mesh/model.c
index 034d544..90bb62d 100644
--- a/mesh/model.c
+++ b/mesh/model.c
#include "mesh/util.h"
#include "mesh/model.h"
+/* Divide and round to ceiling (up) to calculate segment count */
+#define CEILDIV(val, div) (((val) + (div) - 1) / (div))
+
struct mesh_model {
const struct mesh_model_ops *cbs;
void *user_data;
/* Use large MIC if it doesn't affect segmentation */
if (msg_len > 11 && msg_len <= 376) {
- if ((out_len / 12) == ((out_len + 4) / 12)) {
+ if (CEILDIV(out_len, 12) == CEILDIV(out_len + 4, 12)) {
szmic = true;
out_len = msg_len + sizeof(uint64_t);
}