This is part of a much larger file, but this is the only function in question. Here's the issue, if I compile it in gcc unoptimized, I will get everything I want without issues. However, if I try to compile it as gcc -c -pg -02 main.c, I get the following error message
Getting fgets warning when trying to run optimized c file
220 Views Asked by buckywucky At
1
There are 1 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in WARNINGS
- Need assistance suppressing specific UserWarning in Python code execution
- I want to avoid this warning: "Microsoft Office has identified a potential security concern"
- Angular NG0912 Warning: Component ID generation collision detected after upgrading to angular 17
- three js Twarning THREE.PropertyBinding: No target node found for track:
- Google Warning: There is no deobfuscation file associated with this App Bundle
- how to fix release testing warning with ad_id permission
- Getting wrong warning in Dart (possible bug), (The operand can't be null, so the condition is always 'true'.)
- In Android Studio Hedgehog, how can I remove all the non error yellow and grey warning highlights from the scrollbar?
- Python filter warnings to hide repetitions, even if the message changes
- Why am I getting a warning about conflicting distribution on apt update and the system becomes unresponsive after apt upgrade
- Warning: #1292 Truncated incorrect DECIMAL valu
- How do fix the Warning:: " validateDOMNesting(...): <div> cannot appear as a descendant of <p> at div " when using react-simple-keyboard package?
- Extract array value using index stored in pandas dataframe
- VHDL/GHDL: Why does port name hide entity?
- Literal carriage return. Run script through tr -d '\r'
Related Questions in FGETS
- Why does registering a handler function for SIGHUP prevent clicking the "X" to close the XTerm window when waiting for input in PHP CLI?
- fgets executing before printf or scanf statement
- Error writes wrong buffer to file using ftell and fseek (C)
- fgets that doesn't stop at spaces or linebreaks
- Using fgets() together with strcmp() strcmp is not properly comparing
- Why fgets(char* buffer, int size, stdin) don't cause Segmentation Fault all time whenever given input string large enough then size of char buffer[]
- how do i make the program wait till next step until i make my input (i used fgets in c)
- Why does fgets() accept (signed) int for its 'count' argument?
- fgets function not taking user input
- Can't read past EOF in C
- Using scanf to Read and Store Values from a File in C
- Uppercase/lowercase conversion skipping some letters
- How can I use a Pointer to structure in C?
- how the null value '\0' assign in the exacted \n index?
- Functionality of puts
Related Questions in STRTOL
- Memory modification when using strtol() and atoi() functions
- Find overlap between 2 integer conversions of hex strings
- Why is strtol() returning 0x7fffffff instead of the expected 0xAABBCCDD?
- string to integer conversion edgecase handling
- atoi() accepting strings mixed with number
- how to use strtol to parse random number of ints in a string?
- How do u make strtol convert 0
- How can I convert hex encoded string to string in C efficiently
- Proper end pointer with strtol() and "0x"?
- Why this situation was happen? c lib problem while using Windows WSL(ubuntu 20.04)
- atoi and strtol produce erroneous results
- strtol is pointing to original string
- Clang-Tidy: 'fscanf' used to convert a string to an integer value, but function will not report conversion errors; consider using 'strtol' instead
- Getting fgets warning when trying to run optimized c file
- C double printf() when a space is put in my scanf()
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Like any other function that does input,
fgetscould fail for a variety of reasons. As you can find from its documentation, if this happens it will returnNULL. However since you do not look at its return value, you would never know. That's what the compiler is trying to warn you about. If it fails, the arraylinewill not contain valid input, and may contain garbage that would cause your program to misbehave if you try to process it.(There are many situations where some warnings only happen with optimization on; this is because the compiler does a more detailed analysis of the code as part of the optimization process, which makes it more possible for it to detect such issues. But that's a good thing; it's not a problem with optimization or a reason not to use it.)
If
fgetsshould fail, there's no obvious way for your program to recover, so the simplest approach is to just have it quit and display an error message. Theperrorfunction is a convenient way to do that; it prints a human-readable message corresponding to the error code from theerrnovariable whichfgetsshould set.So a rudimentary form of error checking here would be to replace your
fgetsline with:Some things you could improve later:
One possible reason for
fgetsto return NULL is end-of-file: if there was no input at all: the user hit the end-of-file key on their terminal (usually Ctrl-D on Unix, Ctrl-Z on Windows) or redirected input from an empty file. That's not exactly an error, and it won't result in an error code inerrno, soperrormay print a misleading message in this case. Try and fix this bug. You could distinguish the two cases using theferrorfunction.If a line was successfully read but can't be parsed as a number,
strtolwill fail. You currently don't check for that either. Look up how it indicates this failure and handle it accordingly.