Author: cfinck
Date: Fri Jul 3 09:06:35 2015
New Revision: 68335
URL: http://svn.reactos.org/svn/reactos?rev=68335&view=rev
Log:
[LOCALSPL, WINPRINT]
Bugfix: All functions returning multiple elements must only set *pcReturned to the element count on success!
Currently, this was also done when querying the needed buffer size. But for this case, *pcReturned just has to be zeroed.
Modified:
branches/colins-printing-for-freedom/reactos/win32ss/printing/processors/winprint/main.c
branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c
branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c
branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c
Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/processors/winprint/main.c
URL: http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
==============================================================================
--- branches/colins-printing-for-freedom/reactos/win32ss/printing/processors/winprint/main.c [iso-8859-1] (original)
+++ branches/colins-printing-for-freedom/reactos/win32ss/printing/processors/winprint/main.c [iso-8859-1] Fri Jul 3 09:06:35 2015
@@ -107,6 +107,7 @@
EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
{
DWORD cbDatatype;
+ DWORD dwDatatypeCount = 0;
DWORD dwErrorCode;
DWORD dwOffsets[_countof(_pwszDatatypes)];
PCWSTR* pCurrentDatatype;
@@ -129,9 +130,9 @@
*pcbNeeded += sizeof(DATATYPES_INFO_1W) + cbDatatype;
// Also calculate the offset in the output buffer of the pointer to this datatype string.
- *pCurrentOffset = *pcReturned * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
-
- (*pcReturned)++;
+ *pCurrentOffset = dwDatatypeCount * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
+
+ dwDatatypeCount++;
pCurrentOffset++;
}
@@ -153,6 +154,7 @@
*pCurrentOffset = MAXDWORD;
PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
+ *pcReturned = dwDatatypeCount;
dwErrorCode = ERROR_SUCCESS;
Cleanup:
Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c
URL: http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
==============================================================================
--- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] (original)
+++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/jobs.c [iso-8859-1] Fri Jul 3 09:06:35 2015
@@ -898,6 +898,7 @@
LocalEnumJobs(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
{
DWORD dwErrorCode;
+ DWORD i;
PBYTE pEnd = &pStart[cbBuf];
PLOCAL_HANDLE pHandle;
PLOCAL_JOB pJob;
@@ -930,9 +931,10 @@
pFirstJobNode = LookupNodeByIndexSkiplist(&pPrinterHandle->pPrinter->JobList, FirstJob);
// Count the required buffer size and the number of jobs.
+ i = 0;
pNode = pFirstJobNode;
- while (*pcReturned < NoJobs && pNode)
+ while (i < NoJobs && pNode)
{
pJob = (PLOCAL_JOB)pNode->Element;
@@ -943,7 +945,7 @@
_LocalGetJobLevel2(pPrinterHandle, pJob, NULL, NULL, 0, pcbNeeded);
// We stop either when there are no more jobs in the list or when the caller didn't request more, whatever comes first.
- (*pcReturned)++;
+ i++;
pNode = pNode->Next[0];
}
@@ -956,13 +958,13 @@
// Begin counting again and also empty the given buffer.
*pcbNeeded = 0;
- *pcReturned = 0;
ZeroMemory(pStart, cbBuf);
// Now call the same functions again to copy the actual data for each job into the buffer.
+ i = 0;
pNode = pFirstJobNode;
- while (*pcReturned < NoJobs && pNode)
+ while (i < NoJobs && pNode)
{
pJob = (PLOCAL_JOB)pNode->Element;
@@ -976,10 +978,11 @@
goto Cleanup;
// We stop either when there are no more jobs in the list or when the caller didn't request more, whatever comes first.
- (*pcReturned)++;
+ i++;
pNode = pNode->Next[0];
}
+ *pcReturned = i;
dwErrorCode = ERROR_SUCCESS;
Cleanup:
Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c
URL: http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
==============================================================================
--- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] (original)
+++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printers.c [iso-8859-1] Fri Jul 3 09:06:35 2015
@@ -317,8 +317,6 @@
for (i = 0; i < 3; i++)
*pcbNeeded += (wcslen(wszPrintProviderInfo[i]) + 1) * sizeof(WCHAR);
- *pcReturned = 1;
-
// Check if the supplied buffer is large enough.
if (cbBuf < *pcbNeeded)
{
@@ -329,12 +327,15 @@
// Copy over the print processor information.
((PPRINTER_INFO_1W)pPrinterEnum)->Flags = 0;
PackStrings(wszPrintProviderInfo, pPrinterEnum, dwOffsets, &pPrinterEnum[*pcbNeeded]);
+ *pcReturned = 1;
dwErrorCode = ERROR_SUCCESS;
goto Cleanup;
}
}
// Count the required buffer size and the number of printers.
+ i = 0;
+
for (pNode = PrinterList.Head.Next[0]; pNode; pNode = pNode->Next[0])
{
pPrinter = (PLOCAL_PRINTER)pNode->Element;
@@ -347,7 +348,7 @@
cbDescription = cchComputerName * sizeof(WCHAR) + cbName + cbComment + sizeof(WCHAR);
*pcbNeeded += sizeof(PRINTER_INFO_1W) + cchComputerName * sizeof(WCHAR) + cbName + cbComment + cbDescription;
- (*pcReturned)++;
+ i++;
}
// Check if the supplied buffer is large enough.
@@ -360,7 +361,7 @@
// Put the strings right after the last PRINTER_INFO_1W structure.
// Due to all the required string processing, we can't just use PackStrings here :(
pPrinterInfo = pPrinterEnum;
- pPrinterString = pPrinterEnum + *pcReturned * sizeof(PRINTER_INFO_1W);
+ pPrinterString = pPrinterEnum + i * sizeof(PRINTER_INFO_1W);
// Copy over the printer information.
for (pNode = PrinterList.Head.Next[0]; pNode; pNode = pNode->Next[0])
@@ -402,6 +403,7 @@
pPrinterInfo += sizeof(PRINTER_INFO_1W);
}
+ *pcReturned = i;
dwErrorCode = ERROR_SUCCESS;
Cleanup:
Modified: branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c
URL: http://svn.reactos.org/svn/reactos/branches/colins-printing-for-freedom/rea…
==============================================================================
--- branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c [iso-8859-1] (original)
+++ branches/colins-printing-for-freedom/reactos/win32ss/printing/providers/localspl/printprocessors.c [iso-8859-1] Fri Jul 3 09:06:35 2015
@@ -438,6 +438,7 @@
DWORD cchMaxSubKey;
DWORD cchPrintProcessor;
DWORD dwErrorCode;
+ DWORD dwPrintProcessorCount;
DWORD i;
HKEY hKey = NULL;
HKEY hSubKey = NULL;
@@ -475,7 +476,7 @@
}
// Get the number of Print Processors and maximum sub key length.
- dwErrorCode = (DWORD)RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, pcReturned, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL);
+ dwErrorCode = (DWORD)RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, &dwPrintProcessorCount, &cchMaxSubKey, NULL, NULL, NULL, NULL, NULL, NULL);
if (dwErrorCode != ERROR_SUCCESS)
{
ERR("RegQueryInfoKeyW failed with status %lu!\n", dwErrorCode);
@@ -494,7 +495,7 @@
// Determine the required size of the output buffer.
*pcbNeeded = 0;
- for (i = 0; i < *pcReturned; i++)
+ for (i = 0; i < dwPrintProcessorCount; i++)
{
// RegEnumKeyExW sucks! Unlike similar API functions, it only returns the actual numbers of characters copied when you supply a buffer large enough.
// So use pwszTemp with its size cchMaxSubKey for this.
@@ -518,10 +519,10 @@
// Put the Print Processor strings right after the last PRINTPROCESSOR_INFO_1W structure.
pCurrentOutputPrintProcessorInfo = pPrintProcessorInfo;
- pCurrentOutputPrintProcessor = pPrintProcessorInfo + *pcReturned * sizeof(PRINTPROCESSOR_INFO_1W);
+ pCurrentOutputPrintProcessor = pPrintProcessorInfo + dwPrintProcessorCount * sizeof(PRINTPROCESSOR_INFO_1W);
// Copy over all Print Processors.
- for (i = 0; i < *pcReturned; i++)
+ for (i = 0; i < dwPrintProcessorCount; i++)
{
// This isn't really correct, but doesn't cause any harm, because we've extensively checked the size of the supplied buffer above.
cchPrintProcessor = cchMaxSubKey + 1;
@@ -544,6 +545,7 @@
}
// We've finished successfully!
+ *pcReturned = dwPrintProcessorCount;
dwErrorCode = ERROR_SUCCESS;
Cleanup: