Null ascii to unicode conversions in winspool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How about this as a fix for winspool problems in the thread on wine-devel, "Winspool errors with notepad".

http://www.winehq.com/hypermail/wine-devel/2003/02/0064.html

Changelog:
Winspool expects NULLs to be preserved in ascii to unicode conversions.

Index: dlls/winspool/info.c
===================================================================
RCS file: /home/wine/wine/dlls/winspool/info.c,v
retrieving revision 1.70
diff -u -r1.70 info.c
--- dlls/winspool/info.c	23 Jan 2003 23:07:39 -0000	1.70
+++ dlls/winspool/info.c	6 Feb 2003 20:52:05 -0000
@@ -104,6 +104,21 @@
 				      DWORD Level, LPBYTE pDriverInfo,
 				      DWORD cbBuf, LPDWORD pcbNeeded,
 				      BOOL unicode);
+
+/* RtlCreateUnicodeStringFromAsciiz will return an empty string in the buffer
+   if passed a NULL string. This returns NULLs to the result. 
+*/
+static inline PWSTR asciitounicode( UNICODE_STRING * usBufferPtr, LPCSTR src )
+{
+    if ( (src) )
+    {
+        RtlCreateUnicodeStringFromAsciiz(usBufferPtr, src);
+        return usBufferPtr->Buffer;
+    }
+    usBufferPtr->Buffer = NULL; /* so that RtlFreeUnicodeString won't barf */
+    return NULL;
+}
+            
 static void
 WINSPOOL_SetDefaultPrinter(const char *devname, const char *name,BOOL force) {
     char qbuf[200];
@@ -554,29 +569,18 @@
     piW = HeapAlloc(heap, 0, sizeof(*piW));
     memcpy(piW, piA, sizeof(*piW)); /* copy everything first */
     
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pServerName);
-    piW->pServerName = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPrinterName);
-    piW->pPrinterName = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pShareName);
-    piW->pShareName = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPortName);
-    piW->pPortName = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pDriverName);
-    piW->pDriverName = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pComment);
-    piW->pComment = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pLocation);
-    piW->pLocation = usBuffer.Buffer;
+    piW->pServerName = asciitounicode(&usBuffer,piA->pServerName);
+    piW->pPrinterName = asciitounicode(&usBuffer,piA->pPrinterName);
+    piW->pShareName = asciitounicode(&usBuffer,piA->pShareName);
+    piW->pPortName = asciitounicode(&usBuffer,piA->pPortName);
+    piW->pDriverName = asciitounicode(&usBuffer,piA->pDriverName);
+    piW->pComment = asciitounicode(&usBuffer,piA->pComment);
+    piW->pLocation = asciitounicode(&usBuffer,piA->pLocation);
     piW->pDevMode = DEVMODEdupAtoW(heap, piA->pDevMode);
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pSepFile);
-    piW->pSepFile = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pPrintProcessor);
-    piW->pPrintProcessor = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pDatatype);
-    piW->pDatatype = usBuffer.Buffer;
-    RtlCreateUnicodeStringFromAsciiz(&usBuffer,piA->pParameters);
-    piW->pParameters = usBuffer.Buffer;
+    piW->pSepFile = asciitounicode(&usBuffer,piA->pSepFile);
+    piW->pPrintProcessor = asciitounicode(&usBuffer,piA->pPrintProcessor);
+    piW->pDatatype = asciitounicode(&usBuffer,piA->pDatatype);
+    piW->pParameters = asciitounicode(&usBuffer,piA->pParameters);
     return piW;
 }
 
@@ -777,19 +781,19 @@
     UNICODE_STRING lpPrinterNameW;
     UNICODE_STRING usBuffer;
     PRINTER_DEFAULTSW DefaultW, *pDefaultW = NULL;
+    PWSTR pwstrPrinterNameW;
     BOOL ret;
 
-    RtlCreateUnicodeStringFromAsciiz(&lpPrinterNameW,lpPrinterName);
+    pwstrPrinterNameW = asciitounicode(&lpPrinterNameW,lpPrinterName);
 
     if(pDefault) {
-        RtlCreateUnicodeStringFromAsciiz(&usBuffer,pDefault->pDatatype);
-        DefaultW.pDatatype = usBuffer.Buffer;
+        DefaultW.pDatatype = asciitounicode(&usBuffer,pDefault->pDatatype);
 	DefaultW.pDevMode = DEVMODEdupAtoW(GetProcessHeap(),
 					   pDefault->pDevMode);
 	DefaultW.DesiredAccess = pDefault->DesiredAccess;
 	pDefaultW = &DefaultW;
     }
-    ret = OpenPrinterW(lpPrinterNameW.Buffer, phPrinter, pDefaultW);
+    ret = OpenPrinterW(pwstrPrinterNameW, phPrinter, pDefaultW);
     if(pDefault) {
         RtlFreeUnicodeString(&usBuffer);
 	HeapFree(GetProcessHeap(), 0, DefaultW.pDevMode);
@@ -1183,6 +1187,7 @@
 HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
 {
     UNICODE_STRING pNameW;
+    PWSTR pwstrNameW;
     PRINTER_INFO_2W *piW;
     PRINTER_INFO_2A *piA = (PRINTER_INFO_2A*)pPrinter;
     HANDLE ret;
@@ -1193,10 +1198,10 @@
 	SetLastError(ERROR_INVALID_LEVEL);
 	return 0;
     }
-    RtlCreateUnicodeStringFromAsciiz(&pNameW,pName);
+    pwstrNameW = asciitounicode(&pNameW,pName);
     piW = PRINTER_INFO_2AtoW(GetProcessHeap(), piA);
 
-    ret = AddPrinterW(pNameW.Buffer, Level, (LPBYTE)piW);
+    ret = AddPrinterW(pwstrNameW, Level, (LPBYTE)piW);
 
     FREE_PRINTER_INFO_2W(GetProcessHeap(), piW);
     RtlFreeUnicodeString(&pNameW);
@@ -2166,8 +2171,11 @@
 {
     BOOL ret;
     UNICODE_STRING lpszNameW;
+    PWSTR pwstrNameW;
+    
     RtlCreateUnicodeStringFromAsciiz(&lpszNameW,lpszName);
-    ret = WINSPOOL_EnumPrinters(dwType, lpszNameW.Buffer, dwLevel, lpbPrinters, cbBuf,
+    pwstrNameW = asciitounicode(&lpszNameW,lpszName);
+    ret = WINSPOOL_EnumPrinters(dwType, pwstrNameW, dwLevel, lpbPrinters, cbBuf,
 				lpdwNeeded, lpdwReturned, FALSE);
     RtlFreeUnicodeString(&lpszNameW);
     return ret;
@@ -2440,8 +2448,10 @@
 {
     BOOL ret;
     UNICODE_STRING pEnvW;
-    RtlCreateUnicodeStringFromAsciiz(&pEnvW, pEnvironment);
-    ret = WINSPOOL_GetPrinterDriver(hPrinter, pEnvW.Buffer, Level, pDriverInfo,
+    PWSTR pwstrEnvW;
+    
+    pwstrEnvW = asciitounicode(&pEnvW, pEnvironment);
+    ret = WINSPOOL_GetPrinterDriver(hPrinter, pwstrEnvW, Level, pDriverInfo,
 				    cbBuf, pcbNeeded, FALSE);
     RtlFreeUnicodeString(&pEnvW);
     return ret;
@@ -2816,19 +2826,16 @@
                                 LPDWORD pcbNeeded, LPDWORD pcReturned)
 {   BOOL ret;
     UNICODE_STRING pNameW, pEnvironmentW;
+    PWSTR pwstrNameW, pwstrEnvironmentW;
 
-    if(pName)
-        RtlCreateUnicodeStringFromAsciiz(&pNameW, pName);
-    if(pEnvironment)
-        RtlCreateUnicodeStringFromAsciiz(&pEnvironmentW, pEnvironment);
+    pwstrNameW = asciitounicode(&pNameW, pName);
+    pwstrEnvironmentW = asciitounicode(&pEnvironmentW, pEnvironment);
 
-    ret = WINSPOOL_EnumPrinterDrivers(pNameW.Buffer, pEnvironmentW.Buffer,
+    ret = WINSPOOL_EnumPrinterDrivers(pwstrNameW, pwstrEnvironmentW,
                                       Level, pDriverInfo, cbBuf, pcbNeeded,
                                       pcReturned, FALSE);
-    if(pName)
-        RtlFreeUnicodeString(&pNameW);
-    if(pEnvironment)
-        RtlFreeUnicodeString(&pEnvironmentW);
+    RtlFreeUnicodeString(&pNameW);
+    RtlFreeUnicodeString(&pEnvironmentW);
 
     return ret;
 }

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux