Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing const qualifier on format parameter #33

Open
Banzai24-yht opened this issue Jun 20, 2023 · 0 comments
Open

missing const qualifier on format parameter #33

Banzai24-yht opened this issue Jun 20, 2023 · 0 comments

Comments

@Banzai24-yht
Copy link

Banzai24-yht commented Jun 20, 2023

Hello,

I got too much warnings: passing 'const char *' to parameter of type 'char *' discards qualifiers

when using "tpl_map"

I did this patch, but I'd rather use an official version of Tpl, with no local patch. it was tested: ok.

$ git diff

diff --git a/src/tpl.c b/src/tpl.c
index e4f9665..753bf0a 100644
--- a/src/tpl.c
+++ b/src/tpl.c
@@ -309,7 +309,7 @@ char *calc_field_addr(tpl_node *parent, int type,char *struct_addr, int ordinal)
     return struct_addr + offset;
 }

-TPL_API tpl_node *tpl_map(char *fmt,...) {
+TPL_API tpl_node *tpl_map(const char *fmt,...) {
   va_list ap;
   tpl_node *tn;

@@ -319,10 +319,11 @@ TPL_API tpl_node *tpl_map(char *fmt,...) {
   return tn;
 }

-TPL_API tpl_node *tpl_map_va(char *fmt, va_list ap) {
+TPL_API tpl_node *tpl_map_va(const char *fmt, va_list ap) {
     int lparen_level=0,expect_lparen=0,t=0,in_structure=0,ordinal=0;
     int in_nested_structure=0;
-    char *c, *peek, *struct_addr=NULL, *struct_next;
+    const char *c, *peek;
+    char *struct_addr=NULL, *struct_next;
     tpl_node *root,*parent,*n=NULL,*preceding,*iter_start_node=NULL,
              *struct_widest_node=NULL, *np; tpl_pidx *pidx;
     tpl_pound_data *pd;
diff --git a/src/tpl.h b/src/tpl.h
index 1da93c4..3067c73 100644
--- a/src/tpl.h
+++ b/src/tpl.h
@@ -116,7 +116,7 @@ typedef struct tpl_gather_t {
 typedef int (tpl_gather_cb)(void *img, size_t sz, void *data);

 /* Prototypes */
-TPL_API tpl_node *tpl_map(char *fmt,...);       /* define tpl using format */
+TPL_API tpl_node *tpl_map(const char *fmt,...);       /* define tpl using format */
 TPL_API void tpl_free(tpl_node *r);             /* free a tpl map */
 TPL_API int tpl_pack(tpl_node *r, int i);       /* pack the n'th packable */
 TPL_API int tpl_unpack(tpl_node *r, int i);     /* unpack the n'th packable */
@@ -127,7 +127,7 @@ TPL_API char* tpl_peek(int mode, ...);         /* sneak peek at format string */
 TPL_API int tpl_gather( int mode, ...);        /* non-blocking image gather */
 TPL_API int tpl_jot(int mode, ...);            /* quick write a simple tpl */

-TPL_API tpl_node *tpl_map_va(char *fmt, va_list ap);
+TPL_API tpl_node *tpl_map_va(const char *fmt, va_list ap);

 #if defined __cplusplus
     }

(END)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant