Skip to content

8336292: [11u] awt_ImagingLib passes arguments to function without a prototype #2854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions make/lib/Awt2dLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBAWT, \
EXTRA_HEADER_DIRS := $(LIBAWT_EXTRA_HEADER_DIRS), \
DISABLED_WARNINGS_gcc := sign-compare unused-result maybe-uninitialized \
format-nonliteral parentheses, \
DISABLED_WARNINGS_clang := logical-op-parentheses extern-initializer, \
DISABLED_WARNINGS_clang := deprecated-non-prototype logical-op-parentheses extern-initializer, \
DISABLED_WARNINGS_solstudio := E_DECLARATION_IN_CODE, \
DISABLED_WARNINGS_microsoft := 4244 4267 4996, \
ASFLAGS := $(LIBAWT_ASFLAGS), \
Expand Down Expand Up @@ -950,7 +950,8 @@ ifeq ($(call isTargetOs, macosx), true)
EXTRA_HEADER_DIRS := $(LIBAWT_LWAWT_EXTRA_HEADER_DIRS), \
DISABLED_WARNINGS_clang := incomplete-implementation enum-conversion \
deprecated-declarations objc-method-access bitwise-op-parentheses \
incompatible-pointer-types parentheses-equality extra-tokens, \
incompatible-pointer-types parentheses-equality extra-tokens \
deprecated-non-prototype, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN) \
-L$(INSTALL_LIBRARIES_HERE), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,29 @@ void decodeDeviceID(UINT32 deviceID, int* card, int* device, int* subdevice,
}


void getDeviceString(char* buffer, int card, int device, int subdevice,
int usePlugHw, int isMidi) {
void getDeviceString(char* buffer, size_t bufferSize, int card, int device,
int subdevice, int usePlugHw, int isMidi) {
if (needEnumerateSubdevices(isMidi)) {
sprintf(buffer, "%s:%d,%d,%d",
snprintf(buffer, bufferSize, "%s:%d,%d,%d",
usePlugHw ? ALSA_PLUGHARDWARE : ALSA_HARDWARE,
card, device, subdevice);
} else {
sprintf(buffer, "%s:%d,%d",
snprintf(buffer, bufferSize, "%s:%d,%d",
usePlugHw ? ALSA_PLUGHARDWARE : ALSA_HARDWARE,
card, device);
}
}


void getDeviceStringFromDeviceID(char* buffer, UINT32 deviceID,
int usePlugHw, int isMidi) {
void getDeviceStringFromDeviceID(char* buffer, size_t bufferSize,
UINT32 deviceID, int usePlugHw, int isMidi) {
int card, device, subdevice;

if (deviceID == ALSA_DEFAULT_DEVICE_ID) {
strcpy(buffer, ALSA_DEFAULT_DEVICE_NAME);
} else {
decodeDeviceID(deviceID, &card, &device, &subdevice, isMidi);
getDeviceString(buffer, card, device, subdevice, usePlugHw, isMidi);
getDeviceString(buffer, bufferSize, card, device, subdevice, usePlugHw, isMidi);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ UINT32 encodeDeviceID(int card, int device, int subdevice);
void decodeDeviceID(UINT32 deviceID, int* card, int* device, int* subdevice,
int isMidi);

void getDeviceStringFromDeviceID(char* buffer, UINT32 deviceID,
int usePlugHw, int isMidi);
void getDeviceStringFromDeviceID(char* buffer, size_t bufferSize,
UINT32 deviceID, int usePlugHw, int isMidi);

void getALSAVersion(char* buffer, int len);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int iterateRawmidiDevices(snd_rawmidi_stream_t direction,
// try to get card info
card = snd_rawmidi_info_get_card(rawmidi_info);
if (card >= 0) {
sprintf(devname, ALSA_HARDWARE_CARD, card);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, card);
if (snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK) >= 0) {
if (snd_ctl_card_info(handle, card_info) >= 0) {
defcardinfo = card_info;
Expand All @@ -121,7 +121,7 @@ static int iterateRawmidiDevices(snd_rawmidi_stream_t direction,
if (snd_card_next(&card) >= 0) {
TRACE1("Found card %d\n", card);
while (doContinue && (card >= 0)) {
sprintf(devname, ALSA_HARDWARE_CARD, card);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, card);
TRACE1("Opening control for alsa rawmidi device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK);
if (err < 0) {
Expand Down Expand Up @@ -230,7 +230,7 @@ static int deviceInfoIterator(UINT32 deviceID, snd_rawmidi_info_t *rawmidi_info,

buffer[0]=' '; buffer[1]='[';
// buffer[300] is enough to store the actual device string w/o overrun
getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_RAWMIDI);
getDeviceStringFromDeviceID(&buffer[2], sizeof(buffer) - 2, deviceID, usePlugHw, ALSA_RAWMIDI);
strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1);
strncpy(desc->name,
(cardinfo != NULL)
Expand Down Expand Up @@ -392,7 +392,7 @@ INT32 openMidiDevice(snd_rawmidi_stream_t direction, INT32 deviceIndex,
// TODO: iterate to get dev ID from index
err = getMidiDeviceID(direction, deviceIndex, &deviceID);
TRACE1(" openMidiDevice(): deviceID: %d\n", (int) deviceID);
getDeviceStringFromDeviceID(devicename, deviceID,
getDeviceStringFromDeviceID(devicename, sizeof(devicename), deviceID,
usePlugHw, ALSA_RAWMIDI);
TRACE1(" openMidiDevice(): deviceString: %s\n", devicename);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int iteratePCMDevices(DeviceIteratorPtr iterator, void* userData) {
// try to get card info
card = snd_pcm_info_get_card(pcminfo);
if (card >= 0) {
sprintf(devname, ALSA_HARDWARE_CARD, card);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, card);
if (snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK) >= 0) {
if (snd_ctl_card_info(handle, cardinfo) >= 0) {
defcardinfo = cardinfo;
Expand All @@ -101,7 +101,7 @@ int iteratePCMDevices(DeviceIteratorPtr iterator, void* userData) {
if (card < 0) {
break;
}
sprintf(devname, ALSA_HARDWARE_CARD, card);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, card);
TRACE1("Opening alsa device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, SND_CTL_NONBLOCK);
if (err < 0) {
Expand Down Expand Up @@ -185,7 +185,7 @@ int deviceInfoIterator(UINT32 deviceID, snd_pcm_info_t* pcminfo,
*desc->deviceID = deviceID;
buffer[0]=' '; buffer[1]='[';
// buffer[300] is enough to store the actual device string w/o overrun
getDeviceStringFromDeviceID(&buffer[2], deviceID, usePlugHw, ALSA_PCM);
getDeviceStringFromDeviceID(&buffer[2], sizeof(buffer) - 2, deviceID, usePlugHw, ALSA_PCM);
strncat(buffer, "]", sizeof(buffer) - strlen(buffer) - 1);
strncpy(desc->name,
(cardinfo != NULL)
Expand Down Expand Up @@ -217,7 +217,7 @@ int openPCMfromDeviceID(int deviceID, snd_pcm_t** handle, int isSource, int hard
int ret;

initAlsaSupport();
getDeviceStringFromDeviceID(buffer, deviceID, !hardware, ALSA_PCM);
getDeviceStringFromDeviceID(buffer, sizeof(buffer), deviceID, !hardware, ALSA_PCM);

TRACE1("Opening ALSA device %s\n", buffer);
ret = snd_pcm_open(handle, buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ INT32 PORT_GetPortMixerCount() {
mixerCount = 0;
if (snd_card_next(&card) >= 0) {
while (card >= 0) {
sprintf(devname, ALSA_HARDWARE_CARD, card);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, card);
TRACE1("PORT_GetPortMixerCount: Opening alsa device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, 0);
if (err < 0) {
Expand Down Expand Up @@ -115,7 +115,7 @@ INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* descr
TRACE0("> PORT_GetPortMixerDescription\n");
snd_ctl_card_info_malloc(&card_info);

sprintf(devname, ALSA_HARDWARE_CARD, (int) mixerIndex);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, (int) mixerIndex);
TRACE1("Opening alsa device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, 0);
if (err < 0) {
Expand All @@ -127,7 +127,7 @@ INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* descr
ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n", (int) mixerIndex, snd_strerror(err));
}
strncpy(description->name, snd_ctl_card_info_get_id(card_info), PORT_STRING_LENGTH - 1);
sprintf(buffer, " [%s]", devname);
snprintf(buffer, sizeof(buffer), " [%s]", devname);
strncat(description->name, buffer, PORT_STRING_LENGTH - 1 - strlen(description->name));
strncpy(description->vendor, "ALSA (http://www.alsa-project.org)", PORT_STRING_LENGTH - 1);
strncpy(description->description, snd_ctl_card_info_get_name(card_info), PORT_STRING_LENGTH - 1);
Expand All @@ -149,7 +149,7 @@ void* PORT_Open(INT32 mixerIndex) {
PortMixer* handle;

TRACE0("> PORT_Open\n");
sprintf(devname, ALSA_HARDWARE_CARD, (int) mixerIndex);
snprintf(devname, sizeof(devname), ALSA_HARDWARE_CARD, (int) mixerIndex);
if ((err = snd_mixer_open(&mixer_handle, 0)) < 0) {
ERROR2("Mixer %s open error: %s", devname, snd_strerror(err));
return NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ + (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont
#define AWT_FONT_CLEANUP_FINISH \
if (_fontThrowJavaException == YES) { \
char s[512]; \
sprintf(s, "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \
snprintf(s, sizeof(s), "%s-%s:%d", __FILE__, __FUNCTION__, __LINE__); \
JNU_ThrowByName(env, "java/lang/RuntimeException", s); \
}

Expand Down
2 changes: 1 addition & 1 deletion src/java.desktop/share/native/common/awt/debug/debug_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void DMem_DumpHeader(MemoryBlockHeader * header) {
"-------";

DMem_VerifyHeader(header);
sprintf(report, reportFormat, header->filename, header->linenumber, header->size, header->order);
snprintf(report, sizeof(report), reportFormat, header->filename, header->linenumber, header->size, header->order);
DTRACE_PRINTLN(report);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void DTrace_VPrintImpl(const char * fmt, va_list arglist) {
DASSERT(fmt != NULL);

/* format the trace message */
vsprintf(DTraceBuffer, fmt, arglist);
vsnprintf(DTraceBuffer, sizeof(DTraceBuffer), fmt, arglist);
/* not a real great overflow check (memory would already be hammered) but better than nothing */
DASSERT(strlen(DTraceBuffer) < MAX_TRACE_BUFFER);
/* output the trace message */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* Note that this shader source code includes some "holes" marked by "%s".
* This allows us to build different shader programs (e.g. one for
* 3x3, one for 5x5, and so on) simply by filling in these "holes" with
* a call to sprintf(). See the OGLBufImgOps_CreateConvolveProgram() method
* a call to snprintf(). See the OGLBufImgOps_CreateConvolveProgram() method
* for more details.
*
* REMIND: Currently this shader (and the supporting code in the
Expand Down Expand Up @@ -141,16 +141,16 @@ OGLBufImgOps_CreateConvolveProgram(jint flags)

if (IS_SET(CONVOLVE_EDGE_ZERO_FILL)) {
// EDGE_ZERO_FILL: fill in zero at the edges
sprintf(edge, "sum = vec4(0.0);");
snprintf(edge, sizeof(edge), "sum = vec4(0.0);");
} else {
// EDGE_NO_OP: use the source pixel color at the edges
sprintf(edge,
snprintf(edge, sizeof(edge),
"sum = texture%s(baseImage, gl_TexCoord[0].st);",
target);
}

// compose the final source code string from the various pieces
sprintf(finalSource, convolveShaderSource,
snprintf(finalSource, sizeof(finalSource), convolveShaderSource,
kernelMax, target, edge, target);

convolveProgram = OGLContext_CreateFragmentProgram(finalSource);
Expand Down Expand Up @@ -296,7 +296,7 @@ OGLBufImgOps_DisableConvolveOp(OGLContext *oglc)
* Note that this shader source code includes some "holes" marked by "%s".
* This allows us to build different shader programs (e.g. one for
* GL_TEXTURE_2D targets, one for GL_TEXTURE_RECTANGLE_ARB targets, and so on)
* simply by filling in these "holes" with a call to sprintf(). See the
* simply by filling in these "holes" with a call to snprintf(). See the
* OGLBufImgOps_CreateRescaleProgram() method for more details.
*/
static const char *rescaleShaderSource =
Expand Down Expand Up @@ -360,7 +360,7 @@ OGLBufImgOps_CreateRescaleProgram(jint flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, rescaleShaderSource,
snprintf(finalSource, sizeof(finalSource), rescaleShaderSource,
target, target, preRescale, postRescale);

rescaleProgram = OGLContext_CreateFragmentProgram(finalSource);
Expand Down Expand Up @@ -502,7 +502,7 @@ OGLBufImgOps_DisableRescaleOp(OGLContext *oglc)
* Note that this shader source code includes some "holes" marked by "%s".
* This allows us to build different shader programs (e.g. one for
* GL_TEXTURE_2D targets, one for GL_TEXTURE_RECTANGLE_ARB targets, and so on)
* simply by filling in these "holes" with a call to sprintf(). See the
* simply by filling in these "holes" with a call to snprintf(). See the
* OGLBufImgOps_CreateLookupProgram() method for more details.
*/
static const char *lookupShaderSource =
Expand Down Expand Up @@ -592,7 +592,7 @@ OGLBufImgOps_CreateLookupProgram(jint flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, lookupShaderSource,
snprintf(finalSource, sizeof(finalSource), lookupShaderSource,
target, target, preLookup, alpha, postLookup);

lookupProgram = OGLContext_CreateFragmentProgram(finalSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,15 @@ OGLPaints_CreateMultiGradProgram(jint flags,
}

if (cycleMethod == CYCLE_NONE) {
sprintf(cycleCode, noCycleCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), noCycleCode, texCoordCalcCode);
} else if (cycleMethod == CYCLE_REFLECT) {
sprintf(cycleCode, reflectCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), reflectCode, texCoordCalcCode);
} else { // (cycleMethod == CYCLE_REPEAT)
sprintf(cycleCode, repeatCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), repeatCode, texCoordCalcCode);
}

// compose the final source code string from the various pieces
sprintf(finalSource, multiGradientShaderSource,
snprintf(finalSource, sizeof(finalSource), multiGradientShaderSource,
MAX_COLORS, maxFractions,
maskVars, paintVars, distCode,
cycleCode, colorSpaceCode, maskCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ HandleError(Display * disp, XErrorEvent * err) {
XGetErrorText(disp, err->error_code, msg, sizeof(msg));
fprintf(stderr, "Xerror %s, XID %x, ser# %d\n", msg, err->resourceid,
err->serial);
sprintf(buf, "%d", err->request_code);
snprintf(buf, sizeof(buf), "%d", err->request_code);
XGetErrorDatabaseText(disp, "XRequest", buf, "Unknown", msg, sizeof(msg));
fprintf(stderr, "Major opcode %d (%s)\n", err->request_code, msg);
if (err->request_code > 128) {
Expand Down
24 changes: 12 additions & 12 deletions src/java.desktop/windows/native/libawt/java2d/d3d/D3DShaderGen.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ D3DShaderGen_WriteShader(char *source, char *target, char *name, int flags)
PROCESS_INFORMATION pi;
STARTUPINFO si;
char pargs[300];
sprintf(pargs,
snprintf(pargs, sizeof(pargs),
"c:\\progra~1\\mi5889~1\\utilit~1\\bin\\x86\\fxc.exe "
"/T %s /Vn %s%d /Fh tmp.h tmp.hlsl",
// uncomment the following line to generate debug
Expand Down Expand Up @@ -144,13 +144,13 @@ D3DShaderGen_WriteShaderArray(char *name, int num)
char elem[30];
int i;

sprintf(array, "const DWORD *%sShaders[] =\n{\n", name);
snprintf(array, sizeof(array), "const DWORD *%sShaders[] =\n{\n", name);
for (i = 0; i < num; i++) {
if (num == 32 && EXTRACT_CYCLE_METHOD(i) == 3) {
// REMIND: what a hack!
sprintf(elem, " NULL,\n");
snprintf(elem, sizeof(elem), " NULL,\n");
} else {
sprintf(elem, " %s%d,\n", name, i);
snprintf(elem, sizeof(elem), " %s%d,\n", name, i);
}
strcat(array, elem);
}
Expand Down Expand Up @@ -225,7 +225,7 @@ D3DShaderGen_GenerateConvolveShader(int flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, convolveShaderSource,
snprintf(finalSource, sizeof(finalSource), convolveShaderSource,
kernelMax, edge, kernelMax);

D3DShaderGen_WritePixelShader(finalSource, "convolve", flags);
Expand Down Expand Up @@ -283,7 +283,7 @@ D3DShaderGen_GenerateRescaleShader(int flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, rescaleShaderSource,
snprintf(finalSource, sizeof(finalSource), rescaleShaderSource,
preRescale, postRescale);

D3DShaderGen_WritePixelShader(finalSource, "rescale", flags);
Expand Down Expand Up @@ -357,7 +357,7 @@ D3DShaderGen_GenerateLookupShader(int flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, lookupShaderSource,
snprintf(finalSource, sizeof(finalSource), lookupShaderSource,
preLookup, alpha, postLookup);

D3DShaderGen_WritePixelShader(finalSource, "lookup", flags);
Expand Down Expand Up @@ -452,7 +452,7 @@ D3DShaderGen_GenerateBasicGradShader(int flags)
}

// compose the final source code string from the various pieces
sprintf(finalSource, basicGradientShaderSource,
snprintf(finalSource, sizeof(finalSource), basicGradientShaderSource,
maskVars, maskInput, colorSampler, cycleCode, maskCode);

D3DShaderGen_WritePixelShader(finalSource, "grad", flags);
Expand Down Expand Up @@ -665,15 +665,15 @@ D3DShaderGen_GenerateMultiGradShader(int flags, char *name,
}

if (cycleMethod == CYCLE_NONE) {
sprintf(cycleCode, noCycleCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), noCycleCode, texCoordCalcCode);
} else if (cycleMethod == CYCLE_REFLECT) {
sprintf(cycleCode, reflectCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), reflectCode, texCoordCalcCode);
} else { // (cycleMethod == CYCLE_REPEAT)
sprintf(cycleCode, repeatCode, texCoordCalcCode);
snprintf(cycleCode, sizeof(cycleCode), repeatCode, texCoordCalcCode);
}

// compose the final source code string from the various pieces
sprintf(finalSource, multiGradientShaderSource,
snprintf(finalSource, sizeof(finalSource), multiGradientShaderSource,
MAX_COLORS, maxFractions, colorSampler,
maskVars, paintVars, maskInput, colorSampler,
distCode, cycleCode, colorSpaceCode, maskCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ JNIEXPORT void JNICALL Java_sun_awt_shell_Win32ShellFolderManager2_initializeCom
HRESULT hr = ::CoInitialize(NULL);
if (FAILED(hr)) {
char c[64];
sprintf(c, "Could not initialize COM: HRESULT=0x%08X", hr);
snprintf(c, sizeof(c), "Could not initialize COM: HRESULT=0x%08X", hr);
JNU_ThrowInternalError(env, c);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment) {
WIN_MSG(WM_AWT_CREATE_PRINTED_PIXELS)
WIN_MSG(WM_AWT_OBJECTLISTCLEANUP)
default:
sprintf(szBuf, "0x%8.8x(%s):Unknown message 0x%8.8x\n",
snprintf(szBuf, sizeof(szBuf), "0x%8.8x(%s):Unknown message 0x%8.8x\n",
hwnd, szComment, message);
break;
}
Expand Down
Loading