tr24731

Difference between scanf and scanf_s

浪子不回头ぞ 提交于 2019-12-17 03:41:32
问题 What is the difference between scanf and scanf_s ? In the university I have been taught and I am using scanf , but at my personal computer Visual Studio keeps sending this warning. error C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. And I have to change all scanf to scanf_s or the program won't build. (I am using Visual Studio 2013) 回答1: It is a function that belongs specifically to the Microsoft compiler. scanf originally just reads whatever console

Why is rsize_t defined?

感情迁移 提交于 2019-12-13 11:52:00
问题 I found that strncpy_s() is defined under VS2013 as errno_t __cdecl strncpy_s ( _Out_writes_z_(_SizeInBytes) char * _Dst, _In_ rsize_t _SizeInBytes, _In_reads_or_z_(_MaxCount) const char * _Src, _In_ rsize_t _MaxCount ); rsize_t is: typedef size_t rsize_t; I think it's a trick done by Visual Studio . However, I found this function defined as follows on this page errno_t strncpy_s ( char *restrict dest, rsize_t destsz, const char *restrict src, rsize_t count ); Why is rsize_t defined here?

When will the safe string functions of C11 be part of glibc? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 15:56:17
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . The C11 standard Annex K defines a bunch of new safer string functions, all suffixed by _s (e.g. strcpy_s ). Do you know when these new functions will become available in the GNU C library glibc? So far you have to fall back to a third party library like safec. 回答1: Do you

Undefined reference to memcpy_s

ⅰ亾dé卋堺 提交于 2019-12-07 08:35:27
问题 I'm trying to fix an undefined reference to memcpy_s() error. I've included string.h in my file and the memcpy() function works okay, and I've also tried including memory.h . I'm on x64 Windows 7 and using gcc 4.8.1 to compile. #include <stdlib.h> #include <stdio.h> #include <string.h> void doMemCopy(char* buf, size_t buf_size, char* in, int chr) { memcpy_s(buf, buf_size, in, chr); } memory for buf has been allocated in the main function, which calls doMemCpy(buf, 64, in, bytes) . in is a

Undefined reference to memcpy_s

六月ゝ 毕业季﹏ 提交于 2019-12-05 17:59:21
I'm trying to fix an undefined reference to memcpy_s() error. I've included string.h in my file and the memcpy() function works okay, and I've also tried including memory.h . I'm on x64 Windows 7 and using gcc 4.8.1 to compile. #include <stdlib.h> #include <stdio.h> #include <string.h> void doMemCopy(char* buf, size_t buf_size, char* in, int chr) { memcpy_s(buf, buf_size, in, chr); } memory for buf has been allocated in the main function, which calls doMemCpy(buf, 64, in, bytes) . in is a string read from standard input Exact error from cmd terminal: undefined reference to "memcpy_s" collect2

__STDC_LIB_EXT1__ availability in gcc and clang

别等时光非礼了梦想. 提交于 2019-12-05 07:52:48
Since a quick Google search did not find anything, I will try to ask here (since many people involved in gcc/clang hang around here) - What is the status of __STDC_LIB_EXT1__ in gcc/clang? We are developing a cross platform applicataion and I wanted to use some of the safe bounds checking functions from <stdio.h> (which by miracle are available on Visual Studio 2017), but could not compile the code with Xcode 9.2. I assumed maybe the clang version Xcode uses is outdated, but gcc 6.3.0 on Ubuntu behaves the same. I am trying to use tmpnam_s with the following sample: #if defined(__STDC_LIB_EXT1

Missing C11 strerrorlen_s function under MSVC 2017

房东的猫 提交于 2019-12-04 23:55:21
I'm trying to find which header to include for strerrorlen_s function from C11 standard under MSVC 2017 . I need it for allocating space for error message which to get with strerror_s . The code is the following: auto size = strerrorlen_s(errno) + 1; char* errorReason = (char*)alloca(size); strerror_s(errorReason, size, errno); std::ostringstream oss; oss << "Cannot open: " << fileName << " Reason: " << errorReason; throw std::runtime_error(oss.str()); In the documentation are the following words: As with all bounds-checked functions, strerror_s and strerrorlen_s are only guaranteed to be

How can fopen_s be more safe than fopen?

别等时光非礼了梦想. 提交于 2019-12-04 23:51:43
I'm working on legacy code for Windows platform. When I compile the code in VS2013 , it give following warning: error C4996: ' fopen ': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details." And it will also give samiliar warning for sprintf . I understand sprintf_s is more safe than sprintf because of buffer overflow. But how can be fopen_s be more safe than fopen , there is no chance of buffer overflow because fopen doesn't accept an buffer. Can anyone provide an case fopen is unsafe, and

I am having trouble with multiple chars and scanf_s() [duplicate]

白昼怎懂夜的黑 提交于 2019-12-04 05:29:11
问题 This question already has answers here : Reading a character with scanf_s (3 answers) Closed 8 months ago . I'm trying to use scanf_s() to read in multiple values but every time I run the program, I get Unhandled exception at 0x592AD6AC (msvcr120d.dll) in lab 2.exe: 0xC0000005: Access violation writing location 0x00000000. in a popup window. How do I fix this? float inTemp; char inUnit; char outUnit; printf("Please enter the starting temperature with its units and the units\nyou would like to

Scanf_s warning? Skips User Inputs (topics: Runge-Kutta, Epidemic Simulation)

感情迁移 提交于 2019-12-04 04:52:25
问题 This is my first post and I have to admit, I am terrible at programming. I am that guy in the class that works his tail off, but can never seem to grasp programming as well as the rest of my classmates. So please be nice, I will try to explain my problem below. I have the following code (comments removed), but when I run it I get a warning similar to the one listed below. Also, when I run the program, the first user inputted value is allowed, but then all of the sudden, it jumps to the end of