Const correctness and lib/ldb/include/ldb.h

Richard Sharpe realrichardsharpe at
Sun Nov 9 12:48:29 MST 2014


If my understanding of const is correct (which it might not be), then
we can silence this warning:

[1330/4070] Compiling lib/ldb/tests/sample_module.c
../lib/ldb/tests/sample_module.c: In function ‘sample_add’:
../lib/ldb/tests/sample_module.c:33:2: warning: passing argument 1 of
‘ldb_msg_add_fmt’ discards ‘const’ qualifier from pointer target type
[enabled by default]
  ldb_msg_add_fmt(req->op.add.message, "touchedBy", "sample");
In file included from default/include/public/ldb_module.h:36:0,
                 from ../lib/ldb/tests/sample_module.c:27:
default/include/public/ldb.h:1921:5: note: expected ‘struct
ldb_message *’ but argument is of type ‘const struct ldb_message *’
 int ldb_msg_add_fmt(struct ldb_message *msg,

by declaring ldb_msg_add_fmt as:

int ldb_msg_add_fmt(struct ldb_message const *msg,
                    const char *attr_name, const char *fmt, ...)

Since all of the structures we are likely to get a pointer an
ldb_message declare it as const struct ldb_message *xyz (which I
believe is the same as struct ldb_message const *xyz).

Of course, that might spawn lots of other warnings ...

Richard Sharpe

More information about the samba-technical mailing list