From f448bae54ebd24e40aea57f621085c227952446c Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 15 Nov 2007 21:48:24 +0000 Subject: [PATCH] Fix a few more where we need to specify number of TCHARs rather than sizeof buffer --- bindings/java/src/jni/win32/nls.cpp | 2 +- bindings/java/src/jni/win32/pdh.c | 4 ++-- bindings/java/src/jni/win32/registrykey.cpp | 5 +++-- src/os/win32/cpu.c | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/bindings/java/src/jni/win32/nls.cpp b/bindings/java/src/jni/win32/nls.cpp index ebb23465..173d8aaa 100644 --- a/bindings/java/src/jni/win32/nls.cpp +++ b/bindings/java/src/jni/win32/nls.cpp @@ -40,7 +40,7 @@ JNIEXPORT jstring SIGAR_JNI(win32_LocaleInfo_getAttribute) int retval = GetLocaleInfo(lcid, attr, - value, sizeof(value)); + value, sizeof(value) / sizeof(TCHAR)); if (retval) { int len = lstrlen(value); diff --git a/bindings/java/src/jni/win32/pdh.c b/bindings/java/src/jni/win32/pdh.c index 4842a53c..b2f16ae7 100644 --- a/bindings/java/src/jni/win32/pdh.c +++ b/bindings/java/src/jni/win32/pdh.c @@ -431,8 +431,8 @@ JNIEXPORT jobjectArray SIGAR_JNI(win32_Pdh_pdhGetObjects) JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhLookupPerfName) (JNIEnv *env, jclass cur, jint index) { - TCHAR path[MAX_PATH]; - DWORD len = MAX_PATH; /* len is number of TCHAR's, not sizeof(path) */ + TCHAR path[MAX_PATH + 1]; + DWORD len = sizeof(path) / sizeof(TCHAR); /* len is number of TCHAR's, not sizeof(path) */ PDH_STATUS status = PdhLookupPerfNameByIndex(NULL, index, path, &len); diff --git a/bindings/java/src/jni/win32/registrykey.cpp b/bindings/java/src/jni/win32/registrykey.cpp index 9878ab54..9e810f18 100644 --- a/bindings/java/src/jni/win32/registrykey.cpp +++ b/bindings/java/src/jni/win32/registrykey.cpp @@ -57,9 +57,10 @@ JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumKey) { jstring strResult; TCHAR szBuffer[MAX_PATH + 1]; + DWORD len = sizeof(szBuffer) / sizeof(TCHAR); if(RegEnumKey((HKEY)hkey, index, szBuffer, - sizeof(szBuffer)) == ERROR_SUCCESS) + len) == ERROR_SUCCESS) strResult = env->NewString((const jchar *)szBuffer, lstrlen(szBuffer)); else @@ -73,7 +74,7 @@ JNIEXPORT jstring SIGAR_JNI(win32_RegistryKey_RegEnumValueName) { jstring strResult; TCHAR szValueName[MAX_PATH + 1]; - DWORD cbValueName = sizeof(szValueName); + DWORD cbValueName = sizeof(szValueName) / sizeof(TCHAR); if(RegEnumValue((HKEY)hkey, index, szValueName, &cbValueName, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) diff --git a/src/os/win32/cpu.c b/src/os/win32/cpu.c index eb387461..1c79f4a6 100644 --- a/src/os/win32/cpu.c +++ b/src/os/win32/cpu.c @@ -303,7 +303,7 @@ int sigar_cpu_info_get(sigar_t *sigar, sigar_cpu_info_t *info) "HARDWARE\\DESCRIPTION\\System\\CentralProcessor", &key); //just lookup the first id, then assume all cpus are the same. - rc = RegEnumKey(key, 0, id, sizeof(id)); + rc = RegEnumKey(key, 0, id, sizeof(id)/sizeof(TCHAR)); if (rc != ERROR_SUCCESS) { RegCloseKey(key); return rc;