The C Standard, 184.108.40.206 [ISO/IEC 9899:2011], defines the following behavior for
fsetposfunction sets the
mbstate_tobject (if any) and file position indicator for the stream pointed to by
streamaccording to the value of the object pointed to by
pos, which shall be a value obtained from an earlier successful call to the
fgetposfunction on a stream associated with the same file.
fsetpos() function with any other values for
pos is undefined behavior.
Noncompliant Code Example
This noncompliant code example attempts to read three values from a file and then set the file position pointer back to the beginning of the file:
Only the return value of an
fgetpos() call is a valid argument to
fsetpos(); passing a value of type
fpos_t that was created in any other way is undefined behavior.
In this compliant solution, the initial file position indicator is stored by first calling
fgetpos(), which is used to restore the state to the beginning of the file in the later call to
Misuse of the
fsetpos() function can position a file position indicator to an unintended location in the file.
|(customization)||Users can add a custom check for violations of this constraint.|
Can detect common violations of this rule. However, it cannot handle cases in which the value returned by
|LDRA tool suite|
|CERT_C-FIO44-a||Only use values for fsetpos() that are returned from fgetpos()|
|Polyspace Bug Finder|
|Invalid file position||fsetpos() is invoked with a file position argument not obtained from fgetpos()|
Key here (explains table format and definitions)
|ISO/IEC TS 17961:2013||Using a value for fsetpos other than a value returned from fgetpos [xfilepos]||Prior to 2018-01-12: CERT: Unspecified Relationship|
|[ISO/IEC 9899:2011]||220.127.116.11, "The |