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 |
From: SF M. E. <el...@us...> - 2005-08-20 16:26:39
|
> In what way to you think a static analysis tool can help ? Synopsis can't guess the domain > of all possible values, and so can't know if all values are tested for. In the same > line of thought I don't think exceptions are an appropriate means. I imagine that it can be looked up from the function declaraction or definition that the return type is not void. I would like to enforce that the return value will be checked after the function call so that the result will never be ignored. > All synopsis can do is test that the return value is *used* (at least once), and issue a > warning if not. That in itself will already be very useful. Would anybody like to insert a specific security policy if a compiler option for warnings about unused return values is switched off? Would you like to reuse any functionality that is provided by tools like "SPlint", "AntiC" or "Broadway"? Regards, Markus |
From: Stefan S. <se...@sy...> - 2005-08-24 17:47:04
|
SF Markus Elfring wrote: >>In what way to you think a static analysis tool can help ? Synopsis can't guess the domain >>of all possible values, and so can't know if all values are tested for. In the same >>line of thought I don't think exceptions are an appropriate means. > > > I imagine that it can be looked up from the function declaraction or definition that the return type is not void. > I would like to enforce that the return value will be checked after the function call so that the result will never be ignored. That's what I suggested. Checking that the return value is actually used can be done at compile-time. That doesn't involve any code generation, though. Synopsis could just issue a message if it finds a function call with a non-void return value that is not used later on. The hardest part is (again) the required type analysis to do proper overload resolution. That's not supported by OpenC++ (afaik), and for Synopsis It's still in (early) development. As usual, any help would be much appreciated ! Regards, Stefan |
From: SF M. E. <el...@us...> - 2005-08-25 17:44:13
|
> That's what I suggested. Checking that the return value is actually used can be done at > compile-time. That doesn't involve any code generation, though. Synopsis could just issue > a message if it finds a function call with a non-void return value that is not used later on. Can the function declaration or definition be checked for non-void types without overload resolution? Is a usage scanner for return values available already? Can an algorithm be reused to manage and iterate over the references? I see two cases for further consideration. 1. A value is used in a condition expression as a temporary object. 2. The required value was assigned to a variable ago. But you do not know the amount of code between the interesting places in the analysed function. Regards, Markus |
From: Stefan S. <se...@sy...> - 2005-08-25 18:16:09
|
SF Markus Elfring wrote: >>That's what I suggested. Checking that the return value is actually used can be done at >>compile-time. That doesn't involve any code generation, though. Synopsis could just issue >>a message if it finds a function call with a non-void return value that is not used later on. > > > Can the function declaration or definition be checked for non-void types without overload resolution? I don't understand what you are asking. Function declarations / definitions can of course be checked for return types. Overload resolution comes into play when you find a function call expression and you want to find out what the thing is that is being called. A function ? A call operator ? Which version, dependent on the type the argument evaluates to ? > Is a usage scanner for return values available already? What are you referring to ? Function declarations or function call expressions ? > Can an algorithm be reused to manage and iterate over the references? What do you mean by reuse ? Regards, Stefan |
From: SF M. E. <el...@us...> - 2005-08-25 19:19:43
|
> What do you mean by reuse? I hope that I do not suggest to reinvent a "coding wheel" ... I have just found an interesting template. http://synesis.com.au/software/stlsoft/help/classstlsoft_1_1unused__return__value__monitor.html Regards, Markus |