Questions tagged [tr24731]

TR 24731 is a technical report prepared by the ISO C standardization committee, now partially incorporated as optional Annex K in the ISO/IEC 9899:2011 C Standard. Part 1 standardizes some safer bounds-checking functions for use in C and Part 2 relates to functions that do dynamic memory allocation.

The ISO C standardization committee (ISO/IEC JTC1/SC22/WG14) defined two technical reports:

  • TR 24731-1: Extensions to the C Library Part I: Bounds-checking interfaces

    This includes functions such as fopen_s() and strcpy_s() and sprintf_s(), which should be in some sense more secure than earlier analogs in the standard C library, checking for null pointers and buffer overflows. They are based on, but not identical with, functions with the same names in the Microsoft C library.

    It is included as the optional, but normative, Annex K in the current standard, ISO/IEC 9899:2011 'Programming Languages — C'.

    An evaluation from 2015 came to quite unflattering conclusions, basically wanting to recall it completely. n1967 Field Experience with Annex K - Bounds Checking Interfaces

  • TR 24731-2: Extensions to the C Library Part II: Dynamic allocation functions

    This includes functions such as asprintf() and vasprintf() which dynamically allocate enough space for the formatted output, and the getline() and getdelim() functions which are also defined in POSIX 2008, and strdup(). These were not standardized in C 2011.

65 questions
10
votes
6 answers

sprintf_s with a buffer too small

The following code causes an error and kills my application. It makes sense as the buffer is only 10 bytes long and the text is 22 bytes long (buffer overflow). char buffer[10]; int length = sprintf_s( buffer, 10, "1234567890.1234567890." );…
Steven Smethurst
  • 4,495
  • 15
  • 55
  • 92
9
votes
2 answers

Undefined reference to memcpy_s

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…
hydrazone
  • 111
  • 1
  • 1
  • 5
9
votes
2 answers

Is support of Annex K in C11 required for a conforming implementation?

While answering a question that made use of some functions (sscanf_s and sprintf_s) that I thought were not standard C, Daniel Fischer brought to my attention that the functions in question were defined in Annex K. I understand generally that…
jxh
  • 69,070
  • 8
  • 110
  • 193
7
votes
1 answer

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

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…
samba2
  • 468
  • 7
  • 15
7
votes
7 answers

String input using C scanf_s

I've been trying to look for answer myself, but I can't find one. I want to insert a part of the programming that reads in a string like "Hello" and stores and can display it when I want, so that printf("%s", blah); produces Hello. Here's the code…
user3587529
  • 81
  • 1
  • 1
  • 3
6
votes
1 answer

What is unsafe about fopen?

When using fopen(), Microsoft Visual Studio prints: warning C4996: 'fopen' was declared deprecated` The reason given is: This function or variable may be unsafe. Consider using fopen_s instead. What is unsafe about fopen() that's more safe in…
Sebastian
  • 1,839
  • 12
  • 16
6
votes
1 answer

Header for scanf_s function

While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s?
haccks
  • 104,019
  • 25
  • 176
  • 264
3
votes
2 answers

undefined reference to `scanf_s'

I've got a piece of coursework to get done quickly which requires me to be able to debug the code in a certain way. In order to complete the assignment I have to be able to run the program I've been given and use breakpoints to guide the program…
Josh Hitchcock
  • 65
  • 1
  • 1
  • 6
3
votes
1 answer

man pages for optional C11 Annex K functions

As C11 introduced some new functions like char *gets_s(char *str, rsize_t n); how can I find these functions's man pages on Ubuntu 12.04?
likern
  • 3,744
  • 5
  • 36
  • 47
3
votes
2 answers

Best practice for memcpy in C

Is it same deprecated in GNU as in Microsoft C runtime? Is deprecation, if there is such in GNU C, enforced by later standard of C after 89/90 or the compiler? If it's GNU C compiler, since when and does it provide such a secure alternative memory…
Yang
  • 777
  • 1
  • 10
  • 19
2
votes
3 answers

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

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…
2
votes
3 answers

Warnings like 'wcstok': This function or variable may be unsafe. Consider using wcstok_s instead

I am just using these wide character literals in my code to learn about them wchar_t* wpsub = wcstok(names, names_delim); wpsub = wcstok(NULL, names_delim); wchar_t* wcopied=new wchar_t[wcslen(wname) + 1]; strcpy(nameptr,…
munish
  • 4,505
  • 14
  • 53
  • 83
2
votes
4 answers

Using strcpy_s to copy string to char*

I know that when you use strcpy_s you are supposed to supply the size of the destination string as the second parameter. But if the destination string is a char* then I'm not sure I'm doing it right. I have three examples: char* dest = new char; //…
Kurt Dawson
  • 29
  • 1
  • 3
2
votes
2 answers

strtok_s is undefined on os x

I'm trying to use the C11 function strtok_s, which is supposed to be defined in , but clang is giving me a linking error when I try to use it. Compiling this program: #include int main() { char * buffer; char * state; …
hiy
  • 449
  • 5
  • 15
2
votes
3 answers

Dev C++ strtok_s throws [Warning] assignment makes pointer from integer without a cast

I have the following program: #include #include #include int main(int argc, char *argv[]) { char *tp = NULL, *cp = NULL, *next_token = NULL; char TokenListe[] = "Hello,I Am,1"; tp = strtok_s(TokenListe, ",…
user7177818