Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null to pj and use for relocs #15776

Merged
merged 3 commits into from Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion libr/core/cbin.c
Expand Up @@ -1616,7 +1616,11 @@ static int bin_relocs(RCore *r, int mode, int va) {
}

// check if name is available
pj_ks (pj, "name", (relname && strcmp (relname, "")) ? relname : "N/A");
if (relname && *relname) {
pj_ks (pj, "name", relname);
} else {
pj_knull (pj, "name");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about not showing this field just in case there's no name, programatically it will be handled the same when parsing it and it is how its done in other places in r2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not be handled the same in almost all parsers. But whether it is better in this case to omit the entire name or use null is a subjective question. If you prefer to have it removed, I can do that.

}
pj_ks (pj, "demname", mn ? mn : "");
pj_ks (pj, "type", bin_reloc_type_name (reloc));
pj_kn (pj, "vaddr", reloc->vaddr);
Expand Down
2 changes: 2 additions & 0 deletions libr/include/r_util/pj.h
Expand Up @@ -28,13 +28,15 @@ R_API PJ *pj_o(PJ *j);
R_API PJ *pj_a(PJ *j);
/* keys, values */
R_API PJ *pj_k(PJ *j, const char *k);
R_API PJ *pj_knull(PJ *j, const char *k);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont like to use "null" here wwhen all the other cases have 1 letter to define the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propose a better name

R_API PJ *pj_kn(PJ *j, const char *k, ut64 n);
R_API PJ *pj_kN(PJ *j, const char *k, st64 n);
R_API PJ *pj_ks(PJ *j, const char *k, const char *v);
R_API PJ *pj_ki(PJ *j, const char *k, int d);
R_API PJ *pj_kd(PJ *j, const char *k, double d);
R_API PJ *pj_kf(PJ *j, const char *k, float d);
R_API PJ *pj_kb(PJ *j, const char *k, bool v);
R_API PJ *pj_null(PJ *j);
R_API PJ *pj_b(PJ *j, bool v);
R_API PJ *pj_s(PJ *j, const char *k);
R_API PJ *pj_n(PJ *j, ut64 n);
Expand Down
13 changes: 13 additions & 0 deletions libr/util/pj.c
Expand Up @@ -102,6 +102,13 @@ R_API PJ *pj_k(PJ *j, const char *k) {
return j;
}

R_API PJ *pj_knull(PJ *j, const char *k) {
r_return_val_if_fail (j && k, j);
pj_k (j, k);
pj_null (j);
return j;
}

R_API PJ *pj_kn(PJ *j, const char *k, ut64 n) {
r_return_val_if_fail (j && k, j);
pj_k (j, k);
Expand Down Expand Up @@ -152,6 +159,12 @@ R_API PJ *pj_kb(PJ *j, const char *k, bool v) {
return j;
}

R_API PJ *pj_null(PJ *j) {
r_return_val_if_fail (j, j);
pj_raw (j, "null");
return j;
}

R_API PJ *pj_b(PJ *j, bool v) {
r_return_val_if_fail (j, j);
pj_comma (j);
Expand Down