From: SF M. E. <el...@us...> - 2005-08-20 15:54:25
|
> I am not sure if I understand the details. Could you provide an example > of code transformation that OpenC++ or Synopsis should perform? I mean > the code before transformation and after transformation? 1. memory allocation structure* data = malloc(sizeof(structure)); // error: The check for the null pointer may be forgotten. data -> counter = 1; Transformation: // Add this line at the previous comment to avoid a segmentation fault. if (!data) { throw bad_alloc; /* Or do you prefer to call the function "abort" here? */ } 2. mutual exclusion pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; size_t counter = 0; void inc1() { pthread_mutex_lock(&foo_mutex); ++counter; pthread_mutex_unlock(&foo_mutex); } Transformation: int inc2() { int result = pthread_mutex_lock(&m); if (result) return result; ++counter; return pthread_mutex_unlock(&m); } 3. output functions fprintf(my_ostream, "<body>"); Transformation: if (fprintf(my_ostream, "<body>") == EOF) { // What do you want to do here when the string was not completely written to the file? } Regards, Markus |