oa: apply code-review feedback — strcpy_s link fallback + argv cleanup
Follow-up to review-master-upstream-20249999-oa-dcff2f64-6535a4e1.md: - strcpy_s: add an inline fallback implementation right after the declaration, guarded by #ifndef __STDC_LIB_EXT1__. glibc never defines that macro and does not provide the C11 Annex K interfaces, so the bare declaration was an unresolved symbol at link time; the fallback makes magicOA.o self-contained (strcpy_s becomes a defined symbol) while a real Annex K libc still wins. - magicInit.cpp / magicOA.cpp: use `char argvbuf[] = "tclsh"` for the mutable argv string instead of `char[32]` + snprintf.
This commit is contained in:
parent
c332a86a95
commit
36f697d0ef
|
|
@ -301,10 +301,9 @@ int Magicoa_Init(Tcl_Interp *interp) {
|
||||||
return TCL_ERROR;
|
return TCL_ERROR;
|
||||||
#endif
|
#endif
|
||||||
try {
|
try {
|
||||||
char argvbuf[32];
|
char argvbuf[] = "tclsh"; /* mutable: oaDBInit takes char** */
|
||||||
int args=1;
|
int args=1;
|
||||||
snprintf(argvbuf, sizeof(argvbuf), "tclsh");
|
char *argv[] = {argvbuf};
|
||||||
char *argv[] = {&argvbuf[0]};
|
|
||||||
oaDBInit(&args, argv);
|
oaDBInit(&args, argv);
|
||||||
|
|
||||||
} CATCH
|
} CATCH
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,38 @@
|
||||||
#ifndef rsize_t
|
#ifndef rsize_t
|
||||||
#define rsize_t size_t
|
#define rsize_t size_t
|
||||||
#endif
|
#endif
|
||||||
EXTERN_C /*errno_t*/ int strcpy_s(char *__restrict dest, rsize_t destsz, const char *__restrict src); // FIXME glibc does not include
|
EXTERN_C /*errno_t*/ int strcpy_s(char *__restrict dest, rsize_t destsz, const char *__restrict src); // glibc does not provide C11 Annex K
|
||||||
|
|
||||||
|
#ifndef __STDC_LIB_EXT1__
|
||||||
|
/*
|
||||||
|
* Inline fallback for platforms whose C library does not implement the C11
|
||||||
|
* Annex K bounds-checked interfaces (notably glibc, which never defines
|
||||||
|
* __STDC_LIB_EXT1__). Without this the declaration above would be an
|
||||||
|
* unresolved symbol at link time. Copies src into dest (capacity destsz,
|
||||||
|
* including the terminating NUL); on a bad argument or on truncation it empties
|
||||||
|
* dest and returns non-zero, matching strcpy_s's error contract closely enough
|
||||||
|
* for our use.
|
||||||
|
*/
|
||||||
|
EXTERN_C int strcpy_s(char *__restrict dest, rsize_t destsz, const char *__restrict src) {
|
||||||
|
rsize_t i;
|
||||||
|
if (dest == NULL || destsz == 0) {
|
||||||
|
return 22; /* ~EINVAL */
|
||||||
|
}
|
||||||
|
if (src == NULL) {
|
||||||
|
dest[0] = '\0';
|
||||||
|
return 22; /* ~EINVAL */
|
||||||
|
}
|
||||||
|
for (i = 0; i + 1 < destsz && src[i] != '\0'; i++) {
|
||||||
|
dest[i] = src[i];
|
||||||
|
}
|
||||||
|
if (src[i] != '\0') { /* src did not fit */
|
||||||
|
dest[0] = '\0';
|
||||||
|
return 34; /* ~ERANGE */
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* __STDC_LIB_EXT1__ */
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -24,9 +55,8 @@ oaCellView *curCellView;
|
||||||
int
|
int
|
||||||
getTechInfo (const char *techName)
|
getTechInfo (const char *techName)
|
||||||
{
|
{
|
||||||
char argvbuf[32];
|
char argvbuf[] = "tclsh"; /* mutable: oaDBInit takes char** */
|
||||||
snprintf(argvbuf, sizeof(argvbuf), "tclsh");
|
char *argArray[] = {argvbuf};
|
||||||
char *argArray[] = {&argvbuf[0]};
|
|
||||||
int argCount = 1;
|
int argCount = 1;
|
||||||
// initialize OA DB
|
// initialize OA DB
|
||||||
oaDBInit( &argCount, argArray );
|
oaDBInit( &argCount, argArray );
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue