--- freem/src/mlib.c 2025/03/09 19:50:47 1.3 +++ freem/src/mlib.c 2025/04/13 04:22:43 1.6 @@ -1,5 +1,5 @@ /* - * $Id: mlib.c,v 1.3 2025/03/09 19:50:47 snw Exp $ + * $Id: mlib.c,v 1.6 2025/04/13 04:22:43 snw Exp $ * Function prototypes, structs, and macros for FreeM * binding library * @@ -25,6 +25,15 @@ * along with FreeM. If not, see . * * $Log: mlib.c,v $ + * Revision 1.6 2025/04/13 04:22:43 snw + * Fix snprintf calls + * + * Revision 1.5 2025/04/10 01:24:38 snw + * Remove C++ style comments + * + * Revision 1.4 2025/03/24 04:13:11 snw + * Replace action macro dat with fra_dat to avoid symbol conflict on OS/2 + * * Revision 1.3 2025/03/09 19:50:47 snw * Second phase of REUSE compliance and header reformat * @@ -90,7 +99,7 @@ void mref2str(freem_ref_t *ref, char *ke strcat (key, ref->name); } - // ends with EOL + /* ends with EOL */ strncat (key, "\201", 2); } @@ -108,7 +117,7 @@ pid_t freem_init(char *environment_name, errno = 0; strcpy (shm_env, environment_name); - snprintf (config_file, 4096, "%s/freem/%s/freem.conf", SYSCONFDIR, shm_env); + snprintf (config_file, sizeof (config_file) - 1, "%s/freem/%s/freem.conf", SYSCONFDIR, shm_env); init (namespace_name); ierr_sav = ierr; @@ -139,25 +148,25 @@ short freem_get(freem_ref_t *ref) freem_return_io (); - // set up the EOL-delimited string + /* set up the EOL-delimited string */ mref2str (ref, key); switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table to get the local var + /* call into the symbol table to get the local var */ symtab (get_sym, key, result); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; result in &result + /* call into the FreeM global handler; result in &result */ global (get_sym, key, result); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code + /* call into the SSVN code */ ssvn (get_sym, key, result); ref->status = merr (); break; @@ -166,7 +175,7 @@ short freem_get(freem_ref_t *ref) stcnv_m2c (result); - strncpy (ref->value, result, 255); + strncpy (ref->value, result, sizeof (ref->value)); freem_release_io (); @@ -182,24 +191,24 @@ short freem_set(freem_ref_t *ref) mref2str (ref, key); - snprintf (data, 254, "%s\201", ref->value); + snprintf (data, sizeof (data) - 1, "%s\201", ref->value); switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table to set the local var + /* call into the symbol table to set the local var */ symtab (set_sym, key, data); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; data in &data + /* call into the FreeM global handler; data in &data */ global (set_sym, key, data); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code + /* call into the SSVN code */ ssvn (set_sym, key, data); ref->status = merr (); break; @@ -224,19 +233,19 @@ short freem_kill(freem_ref_t *ref) switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table to kill the local var + /* call into the symbol table to kill the local var */ symtab (kill_sym, key, result); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; result in &result + /* call into the FreeM global handler; result in &result */ global (kill_sym, key, result); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code + /* call into the SSVN code */ ssvn (kill_sym, key, result); ref->status = merr (); break; @@ -245,7 +254,7 @@ short freem_kill(freem_ref_t *ref) stcnv_m2c (result); - strncpy (ref->value, result, 255); + strncpy (ref->value, result, sizeof (ref->value) - 1); freem_release_io (); @@ -265,20 +274,20 @@ short freem_data(freem_ref_t *ref) switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table - symtab (dat, key, result); + /* call into the symbol table */ + symtab (fra_dat, key, result); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; result in &result - global (dat, key, result); + /* call into the FreeM global handler; result in &result */ + global (fra_dat, key, result); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code - ssvn (dat, key, result); + /* call into the SSVN code */ + ssvn (fra_dat, key, result); ref->status = merr (); break; @@ -305,19 +314,19 @@ short freem_order(freem_ref_t *ref) switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table for $ORDER + /* call into the symbol table for $ORDER */ symtab (fra_order, key, result); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; result in &result + /* call into the FreeM global handler; result in &result */ global (fra_order, key, result); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code + /* call into the SSVN code */ ssvn (fra_order, key, result); ref->status = merr (); break; @@ -344,19 +353,19 @@ short freem_query(freem_ref_t *ref) switch (ref->reftype) { case MREF_RT_LOCAL: - // call into the symbol table + /* call into the symbol table */ symtab (fra_query, key, result); ref->status = merr (); break; case MREF_RT_GLOBAL: - // call into the FreeM global handler; result in &result + /* call into the FreeM global handler; result in &result */ global (fra_query, key, result); ref->status = merr (); break; case MREF_RT_SSVN: - // call into the SSVN code + /* call into the SSVN code */ ssvn (fra_query, key, result); ref->status = merr (); break; @@ -378,7 +387,7 @@ short freem_lock(freem_ref_t *ref, long char buf[256]; mref2str (ref, key); - snprintf (buf, 255, "+%s\201", key); + snprintf (buf, sizeof (buf) - 1, "+%s\201", key); freem_return_io (); @@ -396,7 +405,7 @@ short freem_unlock(freem_ref_t *ref, lon char buf[256]; mref2str (ref, key); - snprintf (buf, 255, "-%s\201", key); + snprintf (buf, sizeof (buf) - 1, "-%s\201", key); freem_return_io (); @@ -475,7 +484,7 @@ short freem_function(freem_ent_t *ent) stcnv_c2m (buf); sprintf (tmp, "%%ZFRMXEC\201"); symtab (set_sym, tmp, buf); - snprintf ((char *) ztrap, 12, "^%%ZFRMXEC\201"); + snprintf ((char *) ztrap, ZTLEN - 1, "^%%ZFRMXEC\201"); xecline (3); ent->status = merr (); @@ -483,7 +492,7 @@ short freem_function(freem_ent_t *ent) tmp[0] = NUL; ent->value[0] = NUL; - snprintf (tmp, 255, "%%ZFRMRTN\201"); + snprintf (tmp, sizeof (tmp) - 1, "%%ZFRMRTN\201"); symtab (get_sym, tmp, ent->value); stcnv_m2c (ent->value); @@ -536,7 +545,7 @@ short freem_procedure(freem_ent_t *ent) symtab (set_sym, tmp, buf); - snprintf ((char *) ztrap, 12, "^%%ZFRMXEC\201"); + snprintf ((char *) ztrap, ZTLEN - 1, "^%%ZFRMXEC\201"); xecline (3);