C language > Beginner questions

_wmakepath returns incomplete string

(1/2) > >>

sgraffe:
Hello All:
I am not getting correct result from function _wmakepath. The following program demonstrate output from functions _makepath and _wmakepath.

--- Code: ---#include <stdio.h>
#include <stdlib.h>

int main(void)
{
   char path [FILENAME_MAX];
   char drive[] = "C:";
   char dir  [] = "\\foldername\\";
   char name [] = "filename";
   char ext  [] = "txt";

   _makepath(path, drive, dir, name, ext);
   printf("%s \n", path);

   wchar_t wpath [FILENAME_MAX];
   wchar_t wdrive[] = L"C:";
   wchar_t wdir  [] = L"\\foldername\\";
   wchar_t wname [] = L"filename";
   wchar_t wext  [] = L"txt";

   _wmakepath(wpath, wdrive, wdir, wname, wext);
   printf("%ls \n", wpath);

   return 0;
}

--- End code ---
Output:
C:\foldername\filename.txt    (from _makepath)
C:\foldername\                       (from _wmakepath)

Output from _wmakepath is missing the filename and extension components.
Compiler options are: -std:C11 -Tx86-coff -Ot -Ob1 -fp:precise -W1 -Gd -Zx
Version: 8.00.60 (Win64)

Any ideas?

TimoVJL:
You found a bug.

--- Code: ---7703978E  |.  66:833A 00    CMP WORD PTR DS:[EDX],0
77039792  |.  74 2F         JE SHORT 770397C3
77039794  |>  66:8B0A       /MOV CX,WORD PTR DS:[EDX]
77039797  |.  66:8908       |MOV WORD PTR DS:[EAX],CX
7703979A  |.  83C2 02       |ADD EDX,2
7703979D  |.  83C0 02       |ADD EAX,2
770397A0  |.  66:85C9       |TEST CX,CX   <--- bug ? should be CMP WORD PTR DS:[EDX],0
770397A3  |.  74 04         |JZ SHORT 770397A9
770397A5  |.  39F8          |CMP EAX,EDI
770397A7  |.^ 72 EB         \JB SHORT 77039794

--- End code ---

sgraffe:
Oh, thank you, Timo. Shall I copy this message to the Bugs section?

Compiler 1, User 1, :-).

Regards,

TimoVJL:
Sure you can do it.

In attachment a test project to fix that wmakepath bug if someone want to replace it in crt.lib.

sgraffe:
Hello again:

I modified my sample program, and changed the last line to use wprintf instead of printf:

--- Code: ---#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>

int main(void)
{
char path [FILENAME_MAX];
char drive[] = "C:";
char dir  [] = "\\foldername\\";
char name [] = "filename";
char ext  [] = "txt";

_makepath(path, drive, dir, name, ext);
printf("%s \n", path);

wchar_t wpath [FILENAME_MAX];
wchar_t wdrive[] = L"C:";
wchar_t wdir  [] = L"\\foldername\\";
wchar_t wname [] = L"filename";
wchar_t wext  [] = L"txt";

_wmakepath(wpath, wdrive, wdir, wname, wext);
wprintf(L"%ls \n", wpath);

return 0;
}
--- End code ---

now wprintf does not give any output. The output for the program is just
C:\foldername\filename.txt  (the printf at the beginning)

so, is the handling of wchar_t type not reliable?
 

Navigation

[0] Message Index

[#] Next page

Go to full version