Comments (3)
The student code didn't initialize array element[0] (as well as use after return)
from dcc.
Yes they did:
int* getFactors(int num) {
int factors[50];
int count=1;
int localNum = num;
for(int x=2; x <= localNum-1; x++) {
if(num % x == 0) {
factors[count] = x;
count++;
}
}
factors[0] = count;
int *factorPointer = factors;
return factorPointer;
}
Unless I've somehow totally misunderstood:
count variable is created with value 1
factors[0] is set to count (which will be either 1 or a number higher than 1)
*factorPointer = factors (so factorPointer[0] is factors[0] is initialised)
factorPointer is returned
Part of the problem is that the variables seem to have totally reasonable values in them, according to the dcc helpful python/gdb output -- within the function, factors[0] would have actually been 3, and that's what it seems to still have, so it's not at all obvious what the problem is (unless you've seen it before, of course).
from dcc.
OK I understand now - valgrind notices ref below stack pointer. I've added a code to intercept this and explain in 7e5cfd4
from dcc.
Related Issues (20)
- report multidimensional array bounds (incomplete type) errors better.
- can not override dcc's implict -Wunused-variable flag HOT 1
- dcc doesn't accept - for stdin HOT 1
- dcc asan fails to report uninit error when compiled with intermediary object file HOT 1
- dcc dual sanitizer desynchronization when printing pointers HOT 1
- Remap dcc++ to d++ HOT 2
- function name wrongly assumed to be printf for -Wformat-insufficient-args HOT 1
- missign function return type incorrectlky assumed for -Wimplicit-int HOT 1
- values close to the memory poison values not flagged as uninitialized HOT 1
- feature request - report pointer values as pointing to variable HOT 1
- feature request - capture stdin HOT 1
- Uninitialised error detection when using fread HOT 2
- enhancement - give specific (helpful) error for failure to null-terminate string
- fileno broken HOT 1
- printf "%s\n" of a NULL value produces incorrect explanation
- warning NULL argument for printf %s would benefit from explanation
- Request: add explanations of capabilities/limitations to README
- delayed unintialised error when writing to files
- [Docs] help2man man-page generation is missing a [DESCRIPTION] section
- a case where the expected "dcc explanation" output is not generated
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dcc.