How can the below code result in a dangling pointer.
{
char *cPointer = malloc ( some constant number );
/* some code */
free ( cPointer );
cPointer = NULL;
/* some code */
}
Hi Y'all.
I'd like to statistically profile my C code at the instruction level.
I need to know how many additions, multiplications, devides, etc,... I'm performing.
This is not your usual run of the mill code profiling requirement. I'm an algorithm developer and I want to estimate the cost of converting my code to hardware implementations. For this, I'm being asked the instruction call breakdown during run-time (parsing the compiled assembly isn't sufficient as it doesn't consider loops in the code).
After looking around, It seems VMWare may offer a possible solution, but I still couldn't find the specific feature that will allow me to trace the instruction call stream of my process.
Are you aware of any profiling tools which enable this?
I need some help to understand how this code was obfuscated. The code is:
<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>
And the obfuscation is:
\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74
Now I used unescape on the above obfuscated code to read it. What I want to know is what exactly was used to obfuscate the code like that? Basically, I need to customize the readable code to the same obfuscation.
Any help would be greatly appreciated.
I am using below code for javascript window "Yes/No". It is firing twice. Is there any way I can avoid this? Or use any other code?. I need this code behind.
Response.Write("<script language='javascript'> { self.close() }</script>");
I was just wondering, what could possibly be the largest amout of code possible to write a Hello, World! program, without repeating code, without any whitespace, as few newlines as possible, whitout code that doesn't need to be there, and not written in 'Shakespeare'?
Programming language doesn't matter ^^
We are migrating to Sun Studio 12.1 and with the new compiler [ CC: Sun C++ 5.10 SunOS_sparc 2009/06/03 ]. I am getting compilation error while compiling a code that compiled fine with earlier version of Sun Compiler [ CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15 ].
This is the compilation error I get.
"Sample.cc": Error: Could not find a match for LoopThrough(int[2])
needed in main(). 1 Error(s) detected.
* Error code 1.
CODE:
#include <iostream>
#define PRINT_TRACE(STR) \
std::cout << __FILE__ << ":" << __LINE__ << ":" << STR << "\n";
template<size_t SZ>
void LoopThrough(const int(&Item)[SZ])
{
PRINT_TRACE("Specialized version");
for (size_t index = 0; index < SZ; ++index)
{
std::cout << Item[index] << "\n";
}
}
/*
template<typename Type, size_t SZ>
void LoopThrough(const Type(&Item)[SZ])
{
PRINT_TRACE("Generic version");
}
*/
int main()
{
{
int arr[] = { 1, 2 };
LoopThrough(arr);
}
}
If I uncomment the code with Generic version, the code compiles fine and the generic version is called. I don't see this problem with MSVC 2010 with extensions disabled and the same case with ideone here.
The specialized version of the function is called. Now the question is, is this a bug in Sun Compiler ?
If yes, how could we file a bug report ?
im trying to work through some questions and im not sure how to do the following
Q:Find the hard drive sizes that are equal among two or more PCs.
its q15 on this site
http://www.sql-ex.ru/learn_exercises.php#answer_ref
The database scheme consists of four tables:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
any pointers would be appreciated.
I'm trying to get my Javascript code 100% JSLint clean.
I've got some JS code that I've lifted from elsewhere to create a UUID. That code has the following line:
s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1);
This line incites JSLint to generate two error messages:
1) Unexpected use of '&'
2) Unexpected use of '|'
I don't understand why -- I'd appreciate counsel regarding how to recode to eliminate the error message.
When it comes to coding style I'm a pretty relaxed programmer. I'm not firmly dug into a particular coding style. I'd prefer a consistent overall style in a large code base but I'm not going to sweat every little detail of how the code is formatted.
Still there are some coding styles that drive me crazy. No matter what I can't look at examples of these styles without reaching for a VIM buffer to "fix" the "problem". I can't help it. It's not even wrong, I just can't look at it for some reason.
For instance the following comment style almost completely prevents me from actually being able to read the code.
if (someConditional)
// Comment goes here
{
other code
}
What's the most frustrating style you've encountered?
I have the following code:
public bool ProcessData(String data)
{
try
{
result= CheckData(data);
if (TextUtils.isEmpty(result))
{
summary="Data is invalid";
return false;
}
...
finally
{
Period period = new Period(startTime, new LocalDateTime());
String duration = String.format("Duration: %s:%s",
period.getMinutes(), period.getSeconds());
LogCat(duration);
}
return true;
As I learned from this question, the finally block is executed after the return statement. So I modified my code according to that, and in the finally I inserted code that does not modify the output.
Strangely, the code OUTSIDE the finally block does.
My method always returns true.
As suggested, it is not a good idea to have 2 return.
What should I do?
[Edit: see below for final code] I have the following code and I'm trying to figure out where to insert the random.choice code to make it select a single file, copy it, and repeat (here 6 times).
import os
import shutil
import random
dir_input = str(input("Enter Source Directory: "))
src_files = (os.listdir(dir_input))
for x in range (0,5):
print ('This is the %d time' % x)
for file_name in src_files:
full_file_name = (os.path.join(dir_input, file_name))
if (os.path.isfile(full_file_name)):
print ('copying...' + full_file_name)
shutil.copy(full_file_name, r'C:\Dir'))
else:
print ('Finished!')
I'd like to learn other people workflow when using either SVN or GIT.
Please describe your strategy to handle the following tasks:
Implement a feature
Fixing bugs (during development and deployed app)
Code Review
Refactoring code (post code-review)
Incorporate patches
Releasing the newer version of your app (desktop, web, mobile, would you treat them differently?)
Feel free to organize your answer not grouped by the tasks but grouped by whatever you think is relevant but please organize it by VCS/DVCS (please don't mix them).
Thank you.
I'm writing some terrible, terrible code, and I need a way to put a free() in the middle of a statement. The actual code is:
int main(){
return printf("%s", isPalindrome(fgets(malloc(1000), 1000, stdin))?"Yes!\n":"No!\n") >= 0;
// leak 1000 bytes of memory
}
I was using alloca(), but I can't be sure that will actually work on my target computer. My problem is that free returns void, so my code has this error message:
error: void value not ignored as it ought to be
The obvious idea I had was:
int myfree(char *p){
free(p);
return 0;
}
Which is nice in that it makes the code even more unreadable, but I'd prefer not to add another function.
I also briefly tried treating free() as a function pointer, but I don't know if that would work, and I don't know enough about C to do it properly.
Note: I know this is a terrible idea. Don't try this at home kids.
I'm working with VS2005, and SSMS 2005.
SQL Server allows nested comments as follows:
/* Comment 1
/* Comment 2 */
Some commented out code here
*/
This code runs fine. However if putting the above into a .sql file in VS2005, it incorrectly shows the commented out code as 'active', (its not green). It seems that StackOverflow has highlighted the code in the same way.
Is this a bug in VS2005? Or does SSMS handle nested comments differently compared to the ANSI SQL standards?
Can someone clarify this discrepancy, and if it appears to be a bug, if there a way to fix the syntax highlighting?
Does the following code below do the same thing and if so which one is better when coding? And is there a name for when PHP code is missing curly brackets?
The PHP code.
<?php if (isset($_POST['email'])) { echo $_POST['email']; }?>
<?php if (isset($_POST['email'])) echo $_POST['email'];?>
Hello,
I am trying to compile the Enet source code into my code framework for iPhone games. After modifying the header files I get it compiling and linking, but I absolutely must be compiling with the "Compile Source As" set to "Objective-C++" in my xcode project (because the framework code requires this). When I flip this switch in my test project, I get these errors:
Undefined symbols:
"_enet_list_clear", referenced from:
_enet_host_connect in host.o
...
Can anyone help get this linking with "Compile Source As" set to "Objective-C++"?
Hi
I have dragged a empty asp.net table onto my webform. I generate all the rows in the code behind those.
Now my table gets filled up and has dropdown lists. When the user hits save I go through all the rows and update the values from the dropdownlist in the db.
This works all great. However if 2 columns have each have "Present" then those 2 columns should be not be shown anymore and 2 new columns get put in its place with other dropdown lists.
This all works. However you have to refresh the entire page to for the 2 columns that should go away to go away.
So what I tried to do is at the end of the button click event. Clear the whole table and then regenerate it. However when I do this then my values are not saved to the database anymore for whatever reason.
if (IsPostBack == false)
{
// check if dummy variables exist in db- If true just generate tables with values in db. If not generate them.
}
else
{
// grab the values from the database
// generate tables with the values
}
btn click event
{
go through all rows in table(foreach loop)
update each column in the database with cells in each row. while in foreach loop.
//done
}
So this is how it goes and it works expect(all correct values are saved) the table is just not updated to the user.
Does not work
if (IsPostBack == false)
{
// same code as above
}
// if postback is true do nothing. By the time it gets to the click event it says there is zero rows in the table so nothing happens.
btn click event
{
// same code
}
Fails also.
if (IsPostBack == false)
{
// same code as above
}
else
{
// same code as above but moved into its own method.
gernerateTable();
}
btn click event
{
// update all rows
// once done clear the Tables rows
// call generateTable()
}
This last one does nothing as for some reason it does not update anything. I don't understand why.
So what am I doing wrong with this life cycle something in my process is wrong. The code works just not when I want the table to be updated right away.
I want to know about the name of all currently opened MS-Word file by its unique id.
I found unique id for one file but when I gave its destination path in code.
My requirement is that when any user open Word file then the unique id of this file is passed into my code and through this code the name of this file is stored into database (but it is done backgroundly and for multiple files).
I am attempting to convert Java code to Jython and am using the apache Log and LogFactory imports. I am attempting to emulate Foo.class in Jython The chunk of code is as follows:
in Java
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyClass {
private static final Log log = LogFactory.getLog(MyClass.class);
public MyClass(Document dom)
{ //code
}
How can I emulate this same behavior of MyClass.class in Jython/Python?
I am using below formula to move the ball circular, where accelX and accelY are the values from accelerometer, it is working fine.
But the problem in this code is mRadius (I fixed its value to 50), i need to change mRadius according to accelerometer values and also i need bouncing effect when it touches the track. Currently i am developing code by assuming only one ball is on the board.
float degrees = -atan2(accelX, accelY) * 180 / 3.14159;
int x = cCentrePoint.x + mRadius * cos(degreesToRadians(degrees));
int y = cCentrePoint.y + mRadius * sin(degreesToRadians(degrees));
Here is the snap of the game i want to develop:
Updated: I am sending the updated code...
mRadius = 5;
mRange = NSMakeRange(0,60);
-(void) updateBall: (UIAccelerationValue) accelX withY:(UIAccelerationValue)accelY
{
float degrees = -atan2(accelX, accelY) * 180 / 3.14159;
int x = cCentrePoint.x + mRadius * cos(degreesToRadians(degrees));
int y = cCentrePoint.y + mRadius * sin(degreesToRadians(degrees));
//self.targetRect is rect of ball Object
self.targetRect = CGRectMake(newX, newY, 8, 9);
self.currentRect = self.targetRect;
//http://books.google.co.in/books?id=WV9glgdrrrUC&pg=PA455#v=onepage&q=&f=false
static NSDate *lastDrawTime;
if(lastDrawTime!=nil)
{
NSTimeInterval secondsSinceLastDraw = -([lastDrawTime timeIntervalSinceNow]);
ballXVelocity = ballXVelocity + (accelX * secondsSinceLastDraw) * [self isTouchedTrack:mRadius andRange:mRange];
ballYVelocity = ballYVelocity + -(accelY * secondsSinceLastDraw) * [self isTouchedTrack:mRadius andRange:mRange];
distXTravelled = distXTravelled + secondsSinceLastDraw * ballXVelocity * 50;
distYTravelled = distYTravelled + secondsSinceLastDraw * ballYVelocity * 50;
CGRect temp = self.targetRect;
temp.origin.x += distXTravelled;
temp.origin.y += distYTravelled;
int radius = (temp.origin.x - cCentrePoint.x) / cos(degreesToRadians(degrees));
if( !NSLocationInRange(abs(radius),mRange))
{
//Colided with the tracks...Need a better logic here
ballXVelocity = -ballXVelocity;
}
else
{
// Need a better logic here
self.targetRect = temp;
}
//NSLog(@"angle = %f",degrees);
}
[lastDrawTime release];
lastDrawTime = [ [NSDate alloc] init];
}
In the above code i have initialized mRadius and mRange(indicate track) to some constant for testing, i am not getting the moving of the ball as i expected( bouncing effect when Collided with track ) with respect to accelerometer. Help me to recognize where i went wrong or send some code snippets or links which does the similar job.
I am searching for better logic than my code, if you found share with me.
Hi,
I have a peculiar Clearcase doubt. I cannot fully describe why I'm doing such a confusing architecture, but I need to do it (thanks to the mistake done by someone long back).
Ok, here's a bit of detail: B1 is a contaminated branch where both my group's changes and another group's changes got mixed together so badly that there is no way of finding which code is whose). So the solution proposed is to create a new branch called B2 (at the same level as B1) and put all the unmodified code of the other group on it (The way to do that would be to merge B1 with B2 and then go about removing all changes from it till it becomes original). Then create a CR branch on B1 and keep only my group's newly added files or modified files on that branch. Finally create an integration branch out of B2 and merge the changes from CR branch of B1 to integration branch of B2.
So here is what I did: (The use case is where I have dir D where file a, b and c are there. My group ended up modifying file a while b and c are not modified at all).
There is a branch B1 on which there are files a, b and c. There is another branch B2. A merge is done from B1 to B2. Now B2 also has a, b and c.
At this point both branch B1 and B2 are same. Now I delete file a from branch B2 (rmname). Now B2 has b and c only. I put a label to this branch called Label1. This makes the code with label Label1 as the unmodified code from other group.
Now I create a sub branch called CR1 from B1 and delete all the files that are there in B2 branch (i.e b and c) such that it contains only the modified code from original code on it. In my case it is file a.
At this point branch B2 with label Label1 has files b and c (those are unmodified code) and branch CR1 coming off B1 has only a (that is modified by us).
Now I create another branch called integration branch that comes off B2 Label1. And then I do a merge of CR branch on to that expecting that it will have all three files a, b and c for me. All I'd need to do is to do a version tree view and see who modified what.
But the problem I face is that since I had done a rmname of file a on branch B2 earlier to putting Label. The merge does not really take the file a from CR branch.
How to I get around that problem. I want to selectively merge. Is it possible?
sorry if it is a bad design. I'm not really conversant with Clear case and have limited options and time to clear some one else's mess.
I just saw some code in our code base (and it's OLD code, as in Perl 3 or Perl 4 days) that looks like this (I'm simplifying greatly):
my @array;
push( array, $some_scalar );
Notice that the array in the push() doesn't have an @. I would assume that the code behind push knows that the first argument is supposed to be array so grabs the array from the array typeglob. Is that more or less it? If Perl is able to do that without problem, why would you need to include the @ at all?
I have code that's working beautifully on my development machine, but when deployed to the server is throwing null reference exception. So, I can't step through the code, but I've pinned down the culprit. But now I am puzzled. Here's the code. The question is below.
Dim certs = From p In persons _
Select New Certificate( _
p.Value, _
New CertificateData.Seminar(thisEvent.Seminar.Name, _
thisEvent.StartDate.Value, _
thisEvent.EndDate.Value, _
thisEvent.Venue.City, _
thisEvent.Venue.State, _
New CertificateData.Instructor( _
staffMember.Name, _
staffMember.Titles, _
instrSignatPath))) _
With {.CertificateId = p.Key}
lblMessage.Text = CStr(certs Is Nothing)
lblMessage.Text = lblMessage.Text + "<br />" + CStr(certs.Count())
In the code above persons is a dictionary of custom class, and certs is of IEnumerable type. Now here's the quandary.. The first line that sets the label returns False, so certs is not null. But the second line throws an null reference exception. How is this possible?
Is it possible to control the standard streams of C++ code in python? The code is wrapped with SWIG and then exposed to Python where I call one of its functions.
I am getting all kinds of unwanted messages coming from C++ code and I want to suppress them either by not using the output stream or by redirecting it to a bit bucket, e.g. devnull from the os module.