Skip to content
Snippets Groups Projects
Commit ff877a6c authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Validator: remove specific tag for global attribute

Deregistering a global attribute normally is not possible, as basically
every other tag has to be added. This was implemented now.
Originally it was intended to provide the caller with the information,
that a global attribute has to be converted into a local one before
removal. However such internals should not be exposed to the caller. As
it stands there is no real reason to inform a caller, whether an
attribute is local or global. Also, there is a problem that the
predicate is burdened with the possibility, that the attribute doesn't
exists, thus it can't return a boolean directly. Both is why, the
predicate isn't added yet.
Also a bug was detected in the method remove_tag_for_all_attrs. It
removes an attribute while also iterating over it, thus potentially
skipping over some attribute and maybe also invoking undefined behaviour
by deallocating space after the array.
parent bb52ef0c
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,7 @@ FILE_NAME_31=1303;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp ...@@ -64,7 +64,7 @@ FILE_NAME_31=1303;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_32=10846;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8 FILE_NAME_32=10846;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.c;0;8
FILE_NAME_33=1068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8 FILE_NAME_33=1068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag.h;0;8
FILE_NAME_34=1287;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8 FILE_NAME_34=1287;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_tag_data.h;0;8
FILE_NAME_35=23338;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8 FILE_NAME_35=19943;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.c;0;8
FILE_NAME_36=1051;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.h;0;8 FILE_NAME_36=1051;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr.h;0;8
FILE_NAME_37=1413;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr_data.h;0;8 FILE_NAME_37=1413;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator_attr_data.h;0;8
FILE_NAME_38=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8 FILE_NAME_38=924;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fstatus.h;0;8
...@@ -83,8 +83,8 @@ FILE_NAME_50=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp ...@@ -83,8 +83,8 @@ FILE_NAME_50=4221;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_51=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8 FILE_NAME_51=994;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text_mark.c;0;8
FILE_NAME_52=2447;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8 FILE_NAME_52=2447;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_53=9409;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8 FILE_NAME_53=9409;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_tag.c;0;8
FILE_NAME_54=45433;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8 FILE_NAME_54=54966;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator_attr.c;0;8
FILE_NAME_55=556;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8 FILE_NAME_55=521;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
FILE_NAME_56=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4 FILE_NAME_56=201;YAML;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2F.gitlab-ci.yml;0;4
FILE_NAME_57=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8 FILE_NAME_57=71;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Fupload.sh.in;0;8
FILE_NAME_58=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4 FILE_NAME_58=806;Sh;0;EUTF-8;0;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fgitlab-ci%2Frelease.sh.in;0;4
......
...@@ -184,6 +184,19 @@ remove_tag_for_all_attrs (struct SH_Validator * validator, ...@@ -184,6 +184,19 @@ remove_tag_for_all_attrs (struct SH_Validator * validator,
/*@modifies fileSystem@*/ /*@modifies fileSystem@*/
/*@modifies status@*/; /*@modifies status@*/;
static inline
bool
attr_global_remove_tag (struct attr_info * attr,
const struct tag_info * tags,
const size_t tag_n,
const char * tag,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies attr->tags@*/
/*@modifies attr->tag_n@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/;
static inline static inline
bool bool
...@@ -846,6 +859,9 @@ remove_tag_for_all_attrs (struct SH_Validator * validator, ...@@ -846,6 +859,9 @@ remove_tag_for_all_attrs (struct SH_Validator * validator,
{ {
return FALSE; return FALSE;
} }
/* rescan current index,
* as the current attr just vanished */
index--;
} }
} }
else else
...@@ -866,6 +882,47 @@ remove_tag_for_all_attrs (struct SH_Validator * validator, ...@@ -866,6 +882,47 @@ remove_tag_for_all_attrs (struct SH_Validator * validator,
return TRUE; return TRUE;
} }
static inline
bool
attr_global_remove_tag (struct attr_info * attr,
const struct tag_info * tags,
const size_t tag_n,
const char * tag,
/*@null@*/ /*@out@*/ struct SH_Status * status)
/*@modifies attr->tags@*/
/*@modifies attr->tag_n@*/
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
attr->tags = malloc ((tag_n-1) * sizeof (struct attr_tag_info));
if (NULL == attr->tags)
{
set_status (status, E_ALLOC, 3, "malloc failed");
return FALSE;
}
for (size_t index = 0; index < tag_n; index++)
{
size_t position;
/* remove this tag */
if (tag == tags[index].name) continue;
find_attr_tag (attr, tags[index].name, &position);
for (size_t i = attr->tag_n; i > position; i--)
{
attr->tags[i] = attr->tags[i-1];
}
attr->tags[position].name = tags[index].name;
attr->tag_n++;
}
set_success (status);
return TRUE;
}
bool bool
SH_Validator_check_attr (struct SH_Validator * validator, SH_Validator_check_attr (struct SH_Validator * validator,
/*@null@*/ const char * tag, /*@null@*/ const char * tag,
...@@ -1010,6 +1067,19 @@ SH_Validator_deregister_attr (struct SH_Validator * validator, ...@@ -1010,6 +1067,19 @@ SH_Validator_deregister_attr (struct SH_Validator * validator,
return remove_attr (validator, index, status); return remove_attr (validator, index, status);
} }
if ((0 == attr->tag_n) && (1 == validator->tag_n))
{
/* TODO: define whether this is an error */
if (0 != strcmp (tag, validator->tags[0].name))
{
set_status (status, E_VALUE, 2,
"no such tag");
return FALSE;
}
return remove_attr (validator, index, status);
}
if (!find_tag (validator, tag, &index)) if (!find_tag (validator, tag, &index))
{ {
/* TODO: define whether this is an error */ /* TODO: define whether this is an error */
...@@ -1021,11 +1091,10 @@ SH_Validator_deregister_attr (struct SH_Validator * validator, ...@@ -1021,11 +1091,10 @@ SH_Validator_deregister_attr (struct SH_Validator * validator,
if (0 == attr->tag_n) if (0 == attr->tag_n)
{ {
set_status (status, E_STATE, 2, return attr_global_remove_tag (attr,
"can't remove specific tag " validator->tags,
"for global attribute, " validator->tag_n,
"please localize first"); tag, status);
return FALSE;
} }
if (!find_attr_tag (attr, tag, &index)) if (!find_attr_tag (attr, tag, &index))
......
This diff is collapsed.
...@@ -20,7 +20,6 @@ Fragment: ...@@ -20,7 +20,6 @@ Fragment:
Validator: Validator:
- check for global attributes - check for global attributes
- change global to local attribute
- add tag types - add tag types
- fix cursed behaviour, when removing fails - fix cursed behaviour, when removing fails (remove_tag_for_all_attrs)
- initialize from file - initialize from file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment