[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53416] trunk/blender/source/blender: code cleanup: text editor formatting enums were named crypticly, also add asserts if the continuation values are wrong ( which can happen with buffer overflows on formatting).
Campbell Barton
ideasman42 at gmail.com
Sun Dec 30 01:46:21 CET 2012
Revision: 53416
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53416
Author: campbellbarton
Date: 2012-12-30 00:46:17 +0000 (Sun, 30 Dec 2012)
Log Message:
-----------
code cleanup: text editor formatting enums were named crypticly, also add asserts if the continuation values are wrong (which can happen with buffer overflows on formatting).
Modified Paths:
--------------
trunk/blender/source/blender/editors/space_text/text_format.h
trunk/blender/source/blender/editors/space_text/text_format_osl.c
trunk/blender/source/blender/editors/space_text/text_format_py.c
trunk/blender/source/blender/makesdna/DNA_text_types.h
trunk/blender/source/blender/makesrna/intern/rna_object_force.c
Modified: trunk/blender/source/blender/editors/space_text/text_format.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.h 2012-12-30 00:35:17 UTC (rev 53415)
+++ trunk/blender/source/blender/editors/space_text/text_format.h 2012-12-30 00:46:17 UTC (rev 53416)
@@ -41,6 +41,20 @@
int pos, len;
} FlattenString;
+/* format continuation flags (stored just after the NULL terminator) */
+enum {
+ FMT_CONT_NOP = 0, /* no continuation */
+ FMT_CONT_QUOTESINGLE = (1 << 0), /* single quotes */
+ FMT_CONT_QUOTEDOUBLE = (1 << 1), /* double quotes */
+ FMT_CONT_TRIPLE = (1 << 2), /* triplets of quotes: """ or ''' */
+ FMT_CONT_QUOTESINGLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTESINGLE),
+ FMT_CONT_QUOTEDOUBLE_TRIPLE = (FMT_CONT_TRIPLE | FMT_CONT_QUOTEDOUBLE),
+ FMT_CONT_COMMENT_C = (1 << 3), /* multi-line comments, OSL only (C style) */
+ FMT_CONT_COMMENT_CXX = (1 << 4), /* single-line comments, OSL only (C++ style) */
+};
+#define FMT_CONT_ALL \
+ (FMT_CONT_QUOTESINGLE | FMT_CONT_QUOTEDOUBLE | FMT_CONT_TRIPLE | FMT_CONT_COMMENT_C | FMT_CONT_COMMENT_CXX)
+
int flatten_string(struct SpaceText *st, FlattenString *fs, const char *in);
void flatten_string_free(FlattenString *fs);
int flatten_string_strlen(FlattenString *fs, const char *str);
Modified: trunk/blender/source/blender/editors/space_text/text_format_osl.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_osl.c 2012-12-30 00:35:17 UTC (rev 53415)
+++ trunk/blender/source/blender/editors/space_text/text_format_osl.c 2012-12-30 00:46:17 UTC (rev 53416)
@@ -81,7 +81,7 @@
static int txtfmt_osl_find_reserved(const char *string)
{
- int i = 0, len;
+ int i, len;
/* list is from...
* XXX - link to docs!
*/
@@ -121,6 +121,7 @@
else if (STR_LITERAL_STARTSWITH(string, "varying", len)) i = len;
else if (STR_LITERAL_STARTSWITH(string, "virtual", len)) i = len;
else if (STR_LITERAL_STARTSWITH(string, "volatile", len)) i = len;
+ else i = 0;
/* If next source char is an identifier (eg. 'i' in "definate") no match */
if (i == 0 || text_check_identifier(string[i]))
@@ -188,25 +189,27 @@
FlattenString fs;
const char *str;
char *fmt;
- char orig, cont, find, prev = ' ';
+ char cont_orig, cont, find, prev = ' ';
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ BLI_assert((FMT_CONT_ALL & cont) == cont);
}
else {
- cont = 0;
+ cont = FMT_CONT_NOP;
}
/* Get original continuation from this line */
if (line->format != NULL) {
fmt = line->format;
- orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
}
else {
- orig = 0xFF;
+ cont_orig = 0xFF;
}
len = flatten_string(st, &fs, line->line);
@@ -228,14 +231,14 @@
/* Handle continuations */
else if (cont) {
/* C-Style comments */
- if (cont & TXT_CONT_COMMENT_CXX) {
+ if (cont & FMT_CONT_COMMENT_CXX) {
*fmt = '#';
}
- else if (cont & TXT_CONT_COMMENT_C) {
+ else if (cont & FMT_CONT_COMMENT_C) {
if (*str == '*' && *(str + 1) == '/') {
*fmt = '#'; fmt++; str++;
*fmt = '#';
- cont = 0;
+ cont = FMT_CONT_NOP;
}
else {
*fmt = '#';
@@ -243,7 +246,7 @@
/* Handle other comments */
}
else {
- find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
+ find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
if (*str == find) cont = 0;
*fmt = 'l';
}
@@ -254,19 +257,19 @@
else {
/* Deal with comments first */
if (*str == '/' && *(str + 1) == '/') {
- cont = TXT_CONT_COMMENT_CXX;
+ cont = FMT_CONT_COMMENT_CXX;
*fmt = '#';
}
/* C-Style (multi-line) comments */
else if (*str == '/' && *(str + 1) == '*') {
- cont = TXT_CONT_COMMENT_C;
+ cont = FMT_CONT_COMMENT_C;
*fmt = '#'; fmt++; str++;
*fmt = '#';
}
else if (*str == '"' || *str == '\'') {
/* Strings */
find = *str;
- cont = (*str == '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
+ cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE;
*fmt = 'l';
}
/* Whitespace (all ws. has been converted to spaces) */
@@ -312,7 +315,7 @@
*fmt = cont;
/* If continuation has changed and we're allowed, process the next line */
- if (cont != orig && do_next && line->next) {
+ if (cont != cont_orig && do_next && line->next) {
txtfmt_osl_format_line(st, line->next, do_next);
}
Modified: trunk/blender/source/blender/editors/space_text/text_format_py.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_py.c 2012-12-30 00:35:17 UTC (rev 53415)
+++ trunk/blender/source/blender/editors/space_text/text_format_py.c 2012-12-30 00:46:17 UTC (rev 53416)
@@ -159,25 +159,27 @@
FlattenString fs;
const char *str;
char *fmt;
- char orig, cont, find, prev = ' ';
+ char cont_orig, cont, find, prev = ' ';
int len, i;
/* Get continuation from previous line */
if (line->prev && line->prev->format != NULL) {
fmt = line->prev->format;
cont = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ BLI_assert((FMT_CONT_ALL & cont) == cont);
}
else {
- cont = 0;
+ cont = FMT_CONT_NOP;
}
/* Get original continuation from this line */
if (line->format != NULL) {
fmt = line->format;
- orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ cont_orig = fmt[strlen(fmt) + 1]; /* Just after the null-terminator */
+ BLI_assert((FMT_CONT_ALL & cont_orig) == cont_orig);
}
else {
- orig = 0xFF;
+ cont_orig = 0xFF;
}
len = flatten_string(st, &fs, line->line);
@@ -199,18 +201,18 @@
/* Handle continuations */
else if (cont) {
/* Triple strings ("""...""" or '''...''') */
- if (cont & TXT_TRISTR) {
- find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
+ if (cont & FMT_CONT_TRIPLE) {
+ find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
if (*str == find && *(str + 1) == find && *(str + 2) == find) {
*fmt = 'l'; fmt++; str++;
*fmt = 'l'; fmt++; str++;
- cont = 0;
+ cont = FMT_CONT_NOP;
}
/* Handle other strings */
}
else {
- find = (cont & TXT_DBLQUOTSTR) ? '"' : '\'';
- if (*str == find) cont = 0;
+ find = (cont & FMT_CONT_QUOTEDOUBLE) ? '"' : '\'';
+ if (*str == find) cont = FMT_CONT_NOP;
}
*fmt = 'l';
@@ -226,11 +228,11 @@
else if (*str == '"' || *str == '\'') {
/* Strings */
find = *str;
- cont = (*str == '"') ? TXT_DBLQUOTSTR : TXT_SNGQUOTSTR;
+ cont = (*str == '"') ? FMT_CONT_QUOTEDOUBLE : FMT_CONT_QUOTESINGLE;
if (*(str + 1) == find && *(str + 2) == find) {
*fmt = 'l'; fmt++; str++;
*fmt = 'l'; fmt++; str++;
- cont |= TXT_TRISTR;
+ cont |= FMT_CONT_TRIPLE;
}
*fmt = 'l';
}
@@ -287,7 +289,7 @@
*fmt = cont;
/* If continuation has changed and we're allowed, process the next line */
- if (cont != orig && do_next && line->next) {
+ if (cont != cont_orig && do_next && line->next) {
txtfmt_py_format_line(st, line->next, do_next);
}
Modified: trunk/blender/source/blender/makesdna/DNA_text_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_text_types.h 2012-12-30 00:35:17 UTC (rev 53415)
+++ trunk/blender/source/blender/makesdna/DNA_text_types.h 2012-12-30 00:46:17 UTC (rev 53416)
@@ -75,14 +75,4 @@
#define TXT_FOLLOW 0x0200 /* always follow cursor (console) */
#define TXT_TABSTOSPACES 0x0400 /* use space instead of tabs */
-/* format continuation flags */
-#define TXT_NOCONT 0x00 /* no continuation */
-#define TXT_SNGQUOTSTR 0x01 /* single quotes */
-#define TXT_DBLQUOTSTR 0x02 /* double quotes */
-#define TXT_TRISTR 0x04 /* triplets of quotes: """ or ''' */
-#define TXT_SNGTRISTR 0x05 /*(TXT_TRISTR | TXT_SNGQUOTSTR)*/
-#define TXT_DBLTRISTR 0x06 /*(TXT_TRISTR | TXT_DBLQUOTSTR)*/
-#define TXT_CONT_COMMENT_C 0x08 /* multi-line comments, OSL only (C style) */
-#define TXT_CONT_COMMENT_CXX 0x10 /* single-line comments, OSL only (C++ style) */
-
#endif
Modified: trunk/blender/source/blender/makesrna/intern/rna_object_force.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object_force.c 2012-12-30 00:35:17 UTC (rev 53415)
+++ trunk/blender/source/blender/makesrna/intern/rna_object_force.c 2012-12-30 00:46:17 UTC (rev 53416)
@@ -763,8 +763,8 @@
prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
RNA_def_property_int_sdna(prop, NULL, "startframe");
- RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
- RNA_def_property_ui_range(prop, -1000, MAXFRAME, 1, 1);
+ RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
+ RNA_def_property_ui_range(prop, -1000, MAXFRAME, 1, 1);
RNA_def_property_ui_text(prop, "Start", "Frame on which the simulation starts");
prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_TIME);
More information about the Bf-blender-cvs
mailing list