How to find all function calls other than Unicode in source code

In my source code I used Unicode very carefully, I always call broad versions of WinAPI functions, I am very careful in my conversions, etc. etc. to support many users of my program with non-English copies of Windows.

But mistakes are creeping in, as I'm sure you can all understand. Recently, I encountered a program crash, where in one place in my code I called the isspace function, not the iswspace function.

Is there any tool that allows me to scan the source code for all ANSI function calls in order to hopefully find more errors that might be there?

Thanks.

+6
source share
2 answers

I had problems with the software that I worked on a while ago. I found out that the problems are caused by strcpy (), strcat (), etc. And all sorts of string functions that have no protection and can overwrite target buffers if the source has a problem for any reason.

What I was doing at that time was writing a C-parser (I used C later ...) and found all the function calls (which is easy in the C syntax: '(' is a function call if inside the block In C ++ you classes and structures will also have to be detected, but this is not so much.) Now you can generate an error for any function that your software should not use and that breaks your assembly.

C ++ free parsers exist "everywhere", so you can use one of them and reuse this code.

Now there is another way that the preprocessor uses: for any function that you do not want to use your software, you create #define, which when used generates an error:

#define isspace function-error "please use iswspace() instead of isspace()" 

Of course, this means that you need to know the list of such functions in the first place, which, as mentioned above, can be found by looking at the tables of the dynamic library. But as a result, you will not be able to compile your software without first fixing a few things. One of the problems you have to do is in the header file that is included last, or you may get some problems with the library header files:

 #include <boost/shared_ptr.hpp> #include <non_unicode_function.h> ... your functions ... 

This is probably simpler than the C ++ parser, but probably it is still not so much fun ... But if from time to time you need to call a forbidden function, you can make #undef, which you clearly document, etc. d. and then restore the value.

+1
source

Now I have compiled a list of ANSI functions from cplusplus.com. Please be very aware of its limitations, in particular:

a) This does not include any WinAPI functions following the form "... A". b) It does not include any C functions using the Microsoft naming conventions. c) Maybe I made some mistakes.

However, I hope that this will be useful and that the community will help correct any omissions or errors that I may have made.

 isalnum isalpha isblank iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper to_string fprintf fscanf printf scanf snprintf sprintf sscanf vfprintf vfscanf vprintf vscanf vsnprintf vsprintf vsscanf fgetc fgets fputc fputs getc getchar gets putc putchar puts ungetc strtod strtof strtol strtold strtoll strtoul strtoull memcpy memmove memchr strchr strcspn strpbrk strrchr strspn strstr strtok memcmp strcmp strcoll strncmp strxfrm strcat strncat memset strlen strftime regex cmatch smatch csub_match ssub_match isctype toctrans ctrans ctype ctrans_t ctype_t int_t char EOF 
0
source

Source: https://habr.com/ru/post/957208/


All Articles