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