473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Debugging C - Question

3
Hi ,

I was once asked to debug the following code. The code is attached as an image file:

I have found the following Bugs but I would like some other thoughts too :

1 ) Should Bool be a defined type then , succeeded should be initialized to False

2 ) Line 28 : if size_t is defined as long in a 64 bit system then its passsed to uint32 which will make it lose higher 32 bits

3 ) Malloc(0) is a possibility

4) malloc may return error but its not checked or accounted

5) String has to be NULL terminated

6) *s is assigned the allocated and assigned the memory by s is passed..

I hope there are lots more in this. Please post your thoughts

Feb 18 '08 #1
2 1434
gpraghuram
1,275 Expert 1GB
Hi ,

I was once asked to debug the following code. The code is attached as an image file:

I have found the following Bugs but I would like some other thoughts too :

1 ) Should Bool be a defined type then , succeeded should be initialized to False

2 ) Line 28 : if size_t is defined as long in a 64 bit system then its passsed to uint32 which will make it lose higher 32 bits

3 ) Malloc(0) is a possibility

4) malloc may return error but its not checked or accounted

5) String has to be NULL terminated

6) *s is assigned the allocated and assigned the memory by s is passed..

I hope there are lots more in this. Please post your thoughts


1 ) Should Bool be a defined type then , succeeded should be initialized to False
===>Yes, The variable succeeded is not initialized.So in error cases it may return an undefined value
3 ) Malloc(0) is a possibility
===>Yes.
4) malloc may return error but its not checked or accounted
===>So after malloc check for null

Are you expecting something else?

Raghuram
Feb 19 '08 #2
cjava
3
Hi raghu ,

Thanks for replying. I was just curios if there are any other blatant error .

This is one of the questions I was interviewed last year. I was told by the interviewer that there are around lots error. Thats why , I was curious if there are anyother errors.
Feb 19 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
7
by: Frank | last post by:
I'm running a mixed ASP / ASP.NET environment. I can use the debugger in for the ASP.NET code, no problems. But when I turn on ASP Debugging for the project, I get the error message: "Error...
2
by: Alex Clark | last post by:
Hi All, My system: WinXP Pro, VS.NET 2003, SQL Server Personal Edition. I'm having problems with my old favourite demon, SQL Debugging from within VS.NET. I have to say I've found this...
8
by: razael1 | last post by:
I am putting debugging messages into my program by putting blocks that look like this: #ifdef DEBUG errlog << "Here is some information"; #endif All these #ifdef blocks make the code bulky and...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.