Skip to content
Snippets Groups Projects
Commit 9b59288d authored by Anders Lindh Olsson's avatar Anders Lindh Olsson :8ball:
Browse files

Use C++ casts

parent b069c985
No related branches found
No related tags found
No related merge requests found
...@@ -148,7 +148,7 @@ static int parseOp(const char **pp) { ...@@ -148,7 +148,7 @@ static int parseOp(const char **pp) {
skipSpace(p); skipSpace(p);
if (ispunct((unsigned char)*p)) { if (ispunct((unsigned char)*p)) {
for (int o = 1; o < (int)(sizeof(ops) / sizeof(ops[0])); o++) { for (int o = 1; o < static_cast<int>(sizeof(ops) / sizeof(ops[0])); o++) {
int l; int l;
if ((l = startsWith(p, ops[o].str))) { if ((l = startsWith(p, ops[o].str))) {
/* operator found */ /* operator found */
...@@ -369,8 +369,8 @@ static long parseString(const char **pp, const char **pstart) { ...@@ -369,8 +369,8 @@ static long parseString(const char **pp, const char **pstart) {
while (parseSlice(&p, &slice_start, &length)) { while (parseSlice(&p, &slice_start, &length)) {
} }
if (exprDebug) if (exprDebug)
printf("parseString %.*s[%ld,%ld]\n", (int)(p - string_start), string_start, printf("parseString %.*s[%ld,%ld]\n", static_cast<int>(p - string_start),
slice_start, length); string_start, slice_start, length);
if (length && pstart) { if (length && pstart) {
while (slice_start-- > 0) { while (slice_start-- > 0) {
if (*string_start++ == '\\') string_start++; if (*string_start++ == '\\') string_start++;
......
...@@ -386,7 +386,8 @@ static int getRecordHandle(const char *namepart, short type, long minsize, ...@@ -386,7 +386,8 @@ static int getRecordHandle(const char *namepart, short type, long minsize,
long dummy = 0L; long dummy = 0L;
long offset = 0L; long offset = 0L;
sprintf(recordname, "%.*s%s", (int)(PVNAME_STRINGSZ - strlen(namepart) - 1), sprintf(recordname, "%.*s%s",
static_cast<int>(PVNAME_STRINGSZ - strlen(namepart) - 1),
getenv("REQUIRE_IOC"), namepart); getenv("REQUIRE_IOC"), namepart);
if (dbNameToAddr(recordname, paddr) != 0) { if (dbNameToAddr(recordname, paddr) != 0) {
...@@ -431,7 +432,8 @@ must wait until initHooks is loaded before we can register the hook. ...@@ -431,7 +432,8 @@ must wait until initHooks is loaded before we can register the hook.
static void fillModuleListRecord(initHookState state) { static void fillModuleListRecord(initHookState state) {
if (state == initHookAfterFinishDevSup) /* MODULES record exists and has if (state == initHookAfterFinishDevSup) /* MODULES record exists and has
allocated memory */ { allocated memory */
{
DBADDR modules, versions, modver; DBADDR modules, versions, modver;
int have_modules, have_versions, have_modver; int have_modules, have_versions, have_modver;
moduleitem *m; moduleitem *m;
...@@ -455,22 +457,24 @@ static void fillModuleListRecord(initHookState state) { ...@@ -455,22 +457,24 @@ static void fillModuleListRecord(initHookState state) {
if (requireDebug) if (requireDebug)
printf("require: %s[%d] = \"%.*s\"\n", modules.precord->name, i, printf("require: %s[%d] = \"%.*s\"\n", modules.precord->name, i,
MAX_STRING_SIZE - 1, m->content); MAX_STRING_SIZE - 1, m->content);
sprintf((char *)(modules.pfield) + i * MAX_STRING_SIZE, "%.*s", sprintf(reinterpret_cast<char *>(modules.pfield) + i * MAX_STRING_SIZE,
MAX_STRING_SIZE - 1, m->content); "%.*s", MAX_STRING_SIZE - 1, m->content);
} }
if (have_versions) { if (have_versions) {
if (requireDebug) if (requireDebug)
printf("require: %s[%d] = \"%.*s\"\n", versions.precord->name, i, printf("require: %s[%d] = \"%.*s\"\n", versions.precord->name, i,
MAX_STRING_SIZE - 1, m->content + lm); MAX_STRING_SIZE - 1, m->content + lm);
sprintf((char *)(versions.pfield) + i * MAX_STRING_SIZE, "%.*s", sprintf(reinterpret_cast<char *>(versions.pfield) + i * MAX_STRING_SIZE,
MAX_STRING_SIZE - 1, m->content + lm); "%.*s", MAX_STRING_SIZE - 1, m->content + lm);
} }
if (have_modver) { if (have_modver) {
if (requireDebug) if (requireDebug)
printf("require: %s+=\"%-*s%s\"\n", modver.precord->name, printf("require: %s+=\"%-*s%s\"\n", modver.precord->name,
(int)maxModuleNameLength, m->content, m->content + lm); static_cast<int> maxModuleNameLength, m->content,
c += sprintf((char *)(modver.pfield) + c, "%-*s%s\n", m->content + lm);
(int)maxModuleNameLength, m->content, m->content + lm); c += sprintf(reinterpret_cast<char *>(modver.pfield) + c, "%-*s%s\n",
static_cast<int> maxModuleNameLength, m->content,
m->content + lm);
} }
} }
if (have_modules) dbGetRset(&modules)->put_array_info(&modules, i); if (have_modules) dbGetRset(&modules)->put_array_info(&modules, i);
...@@ -506,7 +510,7 @@ void registerModule(const char *module, const char *version, ...@@ -506,7 +510,7 @@ void registerModule(const char *module, const char *version,
absLocation = realpathSeparator(location); absLocation = realpathSeparator(location);
ll = strlen(absLocation) + 1; ll = strlen(absLocation) + 1;
} }
m = (moduleitem *)malloc(sizeof(moduleitem) + lm + lv + ll); m = reinterpret_cast<moduleitem *> malloc(sizeof(moduleitem) + lm + lv + ll);
if (m == NULL) { if (m == NULL) {
fprintf(stderr, "require: out of memory\n"); fprintf(stderr, "require: out of memory\n");
return; return;
...@@ -519,7 +523,8 @@ void registerModule(const char *module, const char *version, ...@@ -519,7 +523,8 @@ void registerModule(const char *module, const char *version,
strcpy(m->content + lm + lv, absLocation ? absLocation : ""); strcpy(m->content + lm + lv, absLocation ? absLocation : "");
free(absLocation); free(absLocation);
for (pm = &loadedModules; *pm != NULL; pm = &(*pm)->next) {} for (pm = &loadedModules; *pm != NULL; pm = &(*pm)->next) {
}
*pm = m; *pm = m;
if (lm > maxModuleNameLength) maxModuleNameLength = lm; if (lm > maxModuleNameLength) maxModuleNameLength = lm;
moduleListBufferSize += lv; moduleListBufferSize += lv;
...@@ -596,10 +601,10 @@ static int findLibRelease(struct dl_phdr_info *info, /* shared library info */ ...@@ -596,10 +601,10 @@ static int findLibRelease(struct dl_phdr_info *info, /* shared library info */
location = name; location = name;
*++p = 0; *++p = 0;
} else { } else {
p = name; /* terminate "<location>/" (if exists) */ p = name; /* terminate "<location>/" (if exists) */
} }
*(symname = p + 2) = '_'; /* replace "lib" with "_" */ *(symname = p + 2) = '_'; /* replace "lib" with "_" */
p = strchr(symname, '.'); /* find ".so" extension */ p = strchr(symname, '.'); /* find ".so" extension */
if (p == NULL) p = symname + strlen(symname); /* no file extension ? */ if (p == NULL) p = symname + strlen(symname); /* no file extension ? */
strcpy(p, "LibRelease"); /* append "LibRelease" to module name */ strcpy(p, "LibRelease"); /* append "LibRelease" to module name */
version = dlsym(handle, symname); /* find symbol "_<module>LibRelease" */ version = dlsym(handle, symname); /* find symbol "_<module>LibRelease" */
...@@ -655,7 +660,7 @@ static void registerExternalModules() { ...@@ -655,7 +660,7 @@ static void registerExternalModules() {
*symname = '_'; /* prefix module name with '_' */ *symname = '_'; /* prefix module name with '_' */
strcpy((p += 2), "LibRelease"); /* append "LibRelease" to module name */ strcpy((p += 2), "LibRelease"); /* append "LibRelease" to module name */
version = (char *)GetProcAddress( version = reinterpret_cast<char *> GetProcAddress(
hMods[i], symname); /* find symbol "_<module>LibRelease" */ hMods[i], symname); /* find symbol "_<module>LibRelease" */
if (version) { if (version) {
*p = 0; *p = 0;
...@@ -737,8 +742,8 @@ int libversionShow(const char *outfile) { ...@@ -737,8 +742,8 @@ int libversionShow(const char *outfile) {
for (m = loadedModules; m; m = m->next) { for (m = loadedModules; m; m = m->next) {
lm = strlen(m->content) + 1; lm = strlen(m->content) + 1;
lv = strlen(m->content + lm) + 1; lv = strlen(m->content + lm) + 1;
fprintf(out, "%-*s%-20s %s\n", (int)maxModuleNameLength, m->content, fprintf(out, "%-*s%-20s %s\n", static_cast<int> maxModuleNameLength,
m->content + lm, m->content + lm + lv); m->content, m->content + lm, m->content + lm + lv);
} }
if (fflush(out) < 0 && outfile) { if (fflush(out) < 0 && outfile) {
fprintf(stderr, "can't write to %s: %s\n", outfile, strerror(errno)); fprintf(stderr, "can't write to %s: %s\n", outfile, strerror(errno));
...@@ -824,8 +829,8 @@ static int compareVersions(const char *found, const char *request, ...@@ -824,8 +829,8 @@ static int compareVersions(const char *found, const char *request,
return MISMATCH; return MISMATCH;
} }
sv_found = (semver_t *)calloc(1, sizeof(semver_t)); sv_found = reinterpret_cast<semver_t *> calloc(1, sizeof(semver_t));
sv_request = (semver_t *)calloc(1, sizeof(semver_t)); sv_request = reinterpret_cast<semver_t *> calloc(1, sizeof(semver_t));
parse_semver(found, sv_found); parse_semver(found, sv_found);
parse_semver(request, sv_request); parse_semver(request, sv_request);
...@@ -1164,9 +1169,9 @@ static int require_priv( ...@@ -1164,9 +1169,9 @@ static int require_priv(
end[2] == OSI_PATH_SEPARATOR[0]) /* "http://..." and friends */ end[2] == OSI_PATH_SEPARATOR[0]) /* "http://..." and friends */
end = strchr(end + 2, OSI_PATH_LIST_SEPARATOR[0]); end = strchr(end + 2, OSI_PATH_LIST_SEPARATOR[0]);
if (end) if (end)
dirlen = (int)(end++ - dirname); dirlen = static_cast<int>(end++ - dirname);
else else
dirlen = (int)strlen(dirname); dirlen = static_cast<int> strlen(dirname);
if (dirlen == 0) continue; /* ignore empty driverpath elements */ if (dirlen == 0) continue; /* ignore empty driverpath elements */
if (requireDebug) printf("require: trying %.*s\n", dirlen, dirname); if (requireDebug) printf("require: trying %.*s\n", dirlen, dirname);
...@@ -1217,7 +1222,9 @@ static int require_priv( ...@@ -1217,7 +1222,9 @@ static int require_priv(
"%s" OSI_PATH_SEPARATOR LIBDIR "%s" OSI_PATH_SEPARATOR LIBDIR
"%s" OSI_PATH_SEPARATOR, "%s" OSI_PATH_SEPARATOR,
currentFilename, targetArch)) { currentFilename, targetArch)) {
/* filename = "<dirname>/[dirlen]<module>/[modulediroffs]<version>/lib/<targetArch>/" */ /* filename =
* "<dirname>/[dirlen]<module>/[modulediroffs]<version>/lib/<targetArch>/"
*/
if (requireDebug) if (requireDebug)
printf("require: %s %s has no support for %s %s\n", module, printf("require: %s %s has no support for %s %s\n", module,
currentFilename, epicsRelease, targetArch); currentFilename, epicsRelease, targetArch);
...@@ -1269,7 +1276,8 @@ static int require_priv( ...@@ -1269,7 +1276,8 @@ static int require_priv(
if (status == EXACT) break; if (status == EXACT) break;
} }
END_DIR_LOOP END_DIR_LOOP
} else { }
else {
/* filename = "<dirname>/[dirlen]<module>/" */ /* filename = "<dirname>/[dirlen]<module>/" */
if (requireDebug) printf("require: no %s directory\n", filename); if (requireDebug) printf("require: no %s directory\n", filename);
...@@ -1279,9 +1287,9 @@ static int require_priv( ...@@ -1279,9 +1287,9 @@ static int require_priv(
/* look for dep file */ /* look for dep file */
releasediroffs = libdiroffs = dirlen; releasediroffs = libdiroffs = dirlen;
if (TRY_FILE(dirlen, "%s%s.dep", module, versionstr)) { if (TRY_FILE(dirlen, "%s%s.dep", module, versionstr)) {
/* filename = /* filename =
"<dirname>/[dirlen][releasediroffs][libdiroffs]<module>(-<version>)?.dep" "<dirname>/[dirlen][releasediroffs][libdiroffs]<module>(-<version>)?.dep"
*/ */
if (requireDebug) printf("require: found old style %s\n", filename); if (requireDebug) printf("require: found old style %s\n", filename);
printf("Module %s%s found in %.*s\n", module, versionstr, dirlen, printf("Module %s%s found in %.*s\n", module, versionstr, dirlen,
filename); filename);
...@@ -1338,9 +1346,9 @@ static int require_priv( ...@@ -1338,9 +1346,9 @@ static int require_priv(
"%s" OSI_PATH_SEPARATOR "%n" LIBDIR "%s" OSI_PATH_SEPARATOR "%s" OSI_PATH_SEPARATOR "%n" LIBDIR "%s" OSI_PATH_SEPARATOR
"%n%s.dep", "%n%s.dep",
founddir, &releasediroffs, targetArch, &libdiroffs, module)) { founddir, &releasediroffs, targetArch, &libdiroffs, module)) {
/* filename = /* filename =
"<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/module.dep" "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/module.dep"
*/ */
fprintf(stderr, "Dependency file %s not found\n", filename); fprintf(stderr, "Dependency file %s not found\n", filename);
} else { } else {
checkdep: checkdep:
...@@ -1357,12 +1365,12 @@ static int require_priv( ...@@ -1357,12 +1365,12 @@ static int require_priv(
if (!(TRY_FILE(libdiroffs, PREFIX "%s" INFIX "%s%n" EXT, module, versionstr, if (!(TRY_FILE(libdiroffs, PREFIX "%s" INFIX "%s%n" EXT, module, versionstr,
&extoffs))) { &extoffs))) {
/* filename = /* filename =
"<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/PREFIX<module>INFIX[extoffs](EXT)?" "<dirname>/[dirlen]<module>/<version>/R<epicsRelease>/[releasediroffs]/lib/<targetArch>/[libdiroffs]/PREFIX<module>INFIX[extoffs](EXT)?"
*/ */
/* or (old) /* or (old)
"<dirname>/[dirlen][releasediroffs][libdiroffs]PREFIX<module>INFIX(-<version>)?[extoffs](EXT)?" "<dirname>/[dirlen][releasediroffs][libdiroffs]PREFIX<module>INFIX(-<version>)?[extoffs](EXT)?"
*/ */
printf("Module %s has no library\n", module); printf("Module %s has no library\n", module);
} else { } else {
loadlib: loadlib:
......
...@@ -76,7 +76,7 @@ int runScript(const char *filename, const char *args) { ...@@ -76,7 +76,7 @@ int runScript(const char *filename, const char *args) {
/* add args to macro definitions */ /* add args to macro definitions */
if (args) { if (args) {
if (runScriptDebug) printf("runScript: macParseDefns \"%s\"\n", args); if (runScriptDebug) printf("runScript: macParseDefns \"%s\"\n", args);
macParseDefns(mac, (char *)args, &pairs); macParseDefns(mac, reinterpret_cast<char *> args, &pairs);
macInstallMacros(mac, pairs); macInstallMacros(mac, pairs);
free(pairs); free(pairs);
} }
...@@ -96,9 +96,9 @@ int runScript(const char *filename, const char *args) { ...@@ -96,9 +96,9 @@ int runScript(const char *filename, const char *args) {
end[2] == OSI_PATH_SEPARATOR[0]) /* "http://..." and friends */ end[2] == OSI_PATH_SEPARATOR[0]) /* "http://..." and friends */
end = strchr(end + 2, OSI_PATH_LIST_SEPARATOR[0]); end = strchr(end + 2, OSI_PATH_LIST_SEPARATOR[0]);
if (end) if (end)
dirlen = (int)(end++ - dirname); dirlen = static_cast<int>(end++ - dirname);
else else
dirlen = (int)strlen(dirname); dirlen = static_cast<int> strlen(dirname);
if (dirlen == 0) continue; /* ignore empty path elements */ if (dirlen == 0) continue; /* ignore empty path elements */
if (dirname[dirlen - 1] == OSI_PATH_SEPARATOR[0]) dirlen--; if (dirname[dirlen - 1] == OSI_PATH_SEPARATOR[0]) dirlen--;
asprintf(&fullname, "%.*s" OSI_PATH_SEPARATOR "%s", dirlen, dirname, asprintf(&fullname, "%.*s" OSI_PATH_SEPARATOR "%s", dirlen, dirname,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment