Skip to content

Commit f924e50

Browse files
djelinskiaivanov-jdk
authored andcommittedFeb 9, 2022
8281440: AWT: Conversion from string literal loses const qualifier
Reviewed-by: prr, aivanov
1 parent 072e7b4 commit f924e50

10 files changed

+22
-22
lines changed
 

‎src/java.desktop/windows/native/libawt/windows/WPrinterJob.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ Java_sun_print_Win32PrintService_getPrinterPort(JNIEnv *env,
729729
}
730730

731731
jstring jPort;
732-
LPTSTR printerName = NULL, printerPort = TEXT("LPT1");
732+
LPTSTR printerName = NULL, printerPort = (LPTSTR)TEXT("LPT1");
733733
LPBYTE buffer = NULL;
734734
DWORD cbBuf = 0;
735735

@@ -745,7 +745,7 @@ Java_sun_print_Win32PrintService_getPrinterPort(JNIEnv *env,
745745
}
746746

747747
if (printerPort == NULL) {
748-
printerPort = TEXT("LPT1");
748+
printerPort = (LPTSTR)TEXT("LPT1");
749749
}
750750
jPort = JNU_NewStringPlatform(env, printerPort);
751751
delete [] buffer;
@@ -1110,7 +1110,7 @@ Java_sun_print_Win32PrintJob_startPrintRawData(JNIEnv *env,
11101110
// Fill in the structure with info about this "document."
11111111
DocInfo.pDocName = jname;
11121112
DocInfo.pOutputFile = NULL;
1113-
DocInfo.pDatatype = TEXT("RAW");
1113+
DocInfo.pDatatype = (LPTSTR)TEXT("RAW");
11141114

11151115
// Inform the spooler the document is beginning.
11161116
if( (::StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo)) == 0 ) {

‎src/java.desktop/windows/native/libawt/windows/awt_Debug.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void AwtDebugSupport::AssertCallback(const char * expr, const char * file, int l
193193
NULL);
194194

195195
if (msgBuffer == NULL) {
196-
msgBuffer = "<Could not get GetLastError() message text>";
196+
msgBuffer = (LPSTR)"<Could not get GetLastError() message text>";
197197
}
198198
// format the assertion message
199199
_snprintf(assertMsg, ASSERT_MSG_SIZE, AssertFmt, expr, file, line, lastError, msgBuffer);

‎src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void AwtDesktopProperties::GetSystemProperties() {
138138
// Note that it uses malloc() and returns the pointer to allocated
139139
// memory, so remember to use free() when you are done with its
140140
// result.
141-
static LPTSTR resolveShellDialogFont(LPTSTR fontName, HKEY handle) {
141+
static LPTSTR resolveShellDialogFont(LPCTSTR fontName, HKEY handle) {
142142
DWORD valueType, valueSize;
143143
if (RegQueryValueEx((HKEY)handle, fontName, NULL,
144144
&valueType, NULL, &valueSize) != 0) {
@@ -164,7 +164,7 @@ static LPTSTR resolveShellDialogFont(LPTSTR fontName, HKEY handle) {
164164
// memory, so remember to use free() when you are done with its
165165
// result.
166166
static LPTSTR resolveShellDialogFont() {
167-
LPTSTR subKey = TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
167+
LPCTSTR subKey = TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
168168

169169
HKEY handle;
170170
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &handle) != 0) {
@@ -183,7 +183,7 @@ static LPTSTR resolveShellDialogFont() {
183183
// Note that it uses malloc() and returns the pointer to allocated
184184
// memory, so remember to use free() when you are done with its
185185
// result.
186-
static LPTSTR getWindowsPropFromReg(LPTSTR subKey, LPTSTR valueName, DWORD *valueType) {
186+
static LPTSTR getWindowsPropFromReg(LPCTSTR subKey, LPCTSTR valueName, DWORD *valueType) {
187187
HKEY handle;
188188
if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &handle) != 0) {
189189
return NULL;
@@ -221,7 +221,7 @@ static LPTSTR getWindowsPropFromReg(LPTSTR subKey, LPTSTR valueName, DWORD *valu
221221
}
222222
}
223223

224-
static LPTSTR getXPStylePropFromReg(LPTSTR valueName) {
224+
static LPTSTR getXPStylePropFromReg(LPCTSTR valueName) {
225225
DWORD valueType;
226226
return getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager"),
227227
valueName, &valueType);
@@ -651,11 +651,11 @@ void AwtDesktopProperties::GetOtherParameters() {
651651
throw;
652652
}
653653

654-
LPTSTR valueName = TEXT("PlaceN");
654+
LPCTSTR valueName = TEXT("PlaceN");
655655
LPTSTR valueNameBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(valueName) + 1), sizeof(TCHAR));
656656
lstrcpy(valueNameBuf, valueName);
657657

658-
LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
658+
LPCTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
659659

660660
LPTSTR propKeyBuf;
661661
try {
@@ -672,7 +672,7 @@ void AwtDesktopProperties::GetOtherParameters() {
672672
valueNameBuf[5] = _T('0' + i++);
673673
propKeyBuf[25] = valueNameBuf[5];
674674

675-
LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar");
675+
LPCTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar");
676676
try {
677677
value = NULL;
678678
if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) {

‎src/java.desktop/windows/native/libawt/windows/awt_DrawingSurface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ extern "C" JNIEXPORT void JNICALL DSUnlockAWT(JNIEnv* env)
275275

276276
// EmbeddedFrame support
277277

278-
static char *const embeddedClassName = "sun/awt/windows/WEmbeddedFrame";
278+
static const char *const embeddedClassName = "sun/awt/windows/WEmbeddedFrame";
279279

280280
JNIEXPORT jobject JNICALL awt_CreateEmbeddedFrame
281281
(JNIEnv* env, void* platformInfo)

‎src/java.desktop/windows/native/libawt/windows/awt_Font.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ AwtFont* AwtFont::Create(JNIEnv *env, jobject font, jint angle, jfloat awScale)
345345
wName = L"Arial";
346346
}
347347

348-
WCHAR* wEName;
348+
LPCWSTR wEName;
349349
if (!wcscmp(wName, L"Helvetica") || !wcscmp(wName, L"SansSerif")) {
350350
wEName = L"Arial";
351351
} else if (!wcscmp(wName, L"TimesRoman") ||
@@ -388,7 +388,7 @@ AwtFont* AwtFont::Create(JNIEnv *env, jobject font, jint angle, jfloat awScale)
388388
return awtFont;
389389
}
390390

391-
static void strip_tail(wchar_t* text, wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
391+
static void strip_tail(wchar_t* text, const wchar_t* tail) { // strips tail and any possible whitespace before it from the end of text
392392
if (wcslen(text)<=wcslen(tail)) {
393393
return;
394394
}
@@ -495,7 +495,7 @@ static HFONT CreateHFont_sub(LPCWSTR name, int style, int height,
495495
return hFont;
496496
}
497497

498-
HFONT AwtFont::CreateHFont(WCHAR* name, int style, int height,
498+
HFONT AwtFont::CreateHFont(LPCWSTR name, int style, int height,
499499
int angle, float awScale)
500500
{
501501
WCHAR longName[80];

‎src/java.desktop/windows/native/libawt/windows/awt_Font.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class AwtFont : public AwtObject {
155155
*/
156156
static AwtFont* Create(JNIEnv *env, jobject font,
157157
jint angle = 0, jfloat awScale=1.0f);
158-
static HFONT CreateHFont(WCHAR* name, int style, int height,
158+
static HFONT CreateHFont(LPCWSTR name, int style, int height,
159159
int angle = 0, float awScale=1.0f);
160160

161161
static void Cleanup();

‎src/java.desktop/windows/native/libawt/windows/awt_PrintControl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ BOOL AwtPrintControl::UpdateAttributes(JNIEnv *env,
10451045
DEVNAMES *devnames = (DEVNAMES*)::GlobalLock(pd.hDevNames);
10461046
DASSERT(!IsBadReadPtr(devnames, sizeof(DEVNAMES)));
10471047
LPTSTR lpcNames = (LPTSTR)devnames;
1048-
LPTSTR pbuf = (_tcslen(lpcNames + devnames->wDeviceOffset) == 0 ?
1048+
LPCTSTR pbuf = (_tcslen(lpcNames + devnames->wDeviceOffset) == 0 ?
10491049
TEXT("") : lpcNames + devnames->wDeviceOffset);
10501050
if (pbuf != NULL) {
10511051
jstring jstr = JNU_NewStringPlatform(env, pbuf);

‎src/java.desktop/windows/native/libawt/windows/awt_PrintJob.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ extern "C" {
6464

6565
/*** Private Constants ***/
6666

67-
static char *kJavaIntStr = "I";
68-
static char *kJavaLongStr = "J";
67+
static const char *kJavaIntStr = "I";
68+
static const char *kJavaLongStr = "J";
6969

7070
/* 2D printing uses 3 byte BGR pixels in Raster printing */
7171
static int J2DRasterBPP = 3;
@@ -1353,7 +1353,7 @@ Java_sun_awt_windows_WPrinterJob__1startDoc(JNIEnv *env, jobject self,
13531353
} else {
13541354
destination = VerifyDestination(env, self);
13551355
}
1356-
LPTSTR docname = NULL;
1356+
LPCTSTR docname = NULL;
13571357
if (jobname != NULL) {
13581358
LPTSTR tmp = (LPTSTR)JNU_GetStringPlatformChars(env, jobname, NULL);
13591359
if (tmp == NULL) {

‎src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void ToolkitThreadProc(void *param)
530530
JNIEnv *env;
531531
JavaVMAttachArgs attachArgs;
532532
attachArgs.version = JNI_VERSION_1_2;
533-
attachArgs.name = "AWT-Windows";
533+
attachArgs.name = (char*)"AWT-Windows";
534534
attachArgs.group = data->threadGroup;
535535

536536
jint res = jvm->AttachCurrentThreadAsDaemon((void **)&env, &attachArgs);

‎src/java.desktop/windows/native/libawt/windows/awt_Win32GraphicsEnv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ Java_sun_awt_Win32FontManager_getEUDCFontFile(JNIEnv *env, jclass cl) {
234234
unsigned long fontPathLen = MAX_PATH + 1;
235235
WCHAR tmpPath[MAX_PATH + 1];
236236
LPWSTR fontPath = fontPathBuf;
237-
LPWSTR eudcKey = NULL;
237+
LPCWSTR eudcKey = NULL;
238238

239239
LANGID langID = GetSystemDefaultLangID();
240240
//lookup for encoding ID, EUDC only supported in

0 commit comments

Comments
 (0)
Please sign in to comment.